Nonchalantly Perusing Magazines

    express-async-handler
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    Simple middleware for handling exceptions inside of async express routes and passing them to your express error handlers.

    Installation:

    npm install --save express-async-handler
    

    or

    yarn add express-async-handler
    

    Usage:

    const asyncHandler = require('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
    })

    Import in Typescript:

    import asyncHandler from "express-async-handler"

    Install

    npm i express-async-handler

    DownloadsWeekly Downloads

    132,151

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    4.81 kB

    Total Files

    6

    Last publish

    Collaborators

    • abazhenov