3.0.0 • Published 4 years ago

@xpbytes/express-async-handler v3.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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)
)
3.0.0

4 years ago

2.1.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago