Skip to content
A high-order function to catch errors from promises.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.npmrc
CHANGELOG.md
LICENSE
README.md
package-lock.json
package.json

README.md

express-catch-errors

Generated by OSS Project Generator.

NPM Version License

A high-order function to catch errors from promises.

Installation

Install package

$ npm install --save express-catch-errors

Usage

  • Router
// user.router.js
const userController = require('./user.controller');

router.get('/users', catchErrors(userController.list));
  • Controller
// user.controller.js
const mongoose = require('mongoose');
const User = mongoose.model('User');

module.exports.list = async (req, res) => {
  const users = await User.find();

  res.json(users);
};

Development

  • Cloning the repo
$ git clone https://github.com/robertoachar/express-catch-errors.git
  • Installing dependencies
$ npm install
  • Running scripts
Action Usage
Starting development mode npm start
Linting code npm run lint

Author

Roberto Achar

License

MIT

You can’t perform that action at this time.