1.0.2 • Published 3 years ago

@forhot2000/express-async-handler v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Simple Middleware to manage exceptions within express routes in asynchronous.

Installation:

npm install --save @forhot2000/express-async-handler

or

yarn add @forhot2000/express-async-handler

Usage:

import asyncHandler from "@forhot2000/express-async-handler"

express.get('/', asyncHandler(async (req, res, next) => {
    const bar = await foo.findAll();
    res.send(bar)
}))

Without express-async-handler

express.get('/',(req, res, next) => {
    foo.findAll()
    .then(bar => {
       res.send(bar)
    })
    .catch(next); // error passed on to the error handling route
})