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

    3.0.0 • Public • Published

    Express Async Handler

    npm NPM Package Version Maintainability

    Utility function to use async functions as express handlers

    yarn add @xpbytes/express-async-handler
    import { asyncHandler } from '@xpbytes/express-async-handler'
     
    app.get(
      '/test',
      asyncHandler(async (req, res, next) => {
        const code = await Promise.resolve(204)
        res.sendStatus(code).end()
      })
    )

    You can optionally give a second argument errorHandler:

    function onError(err, req, res, next) {
      // ...
    }
     
    app.get(
      '/test',
      asyncHandler(async (req, res, next) => {
        const code = await Promise.resolve(204)
        res.sendStatus(code).end()
      }, onError)
    )

    Keywords

    none

    Install

    npm i @xpbytes/express-async-handler

    DownloadsWeekly Downloads

    7

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    5.97 kB

    Total Files

    9

    Last publish

    Collaborators

    • sleeplessbyte
    • vincentrbbmnd
    • thexa4