@xpbytes/express-async-handler
v3.0.0
Published
Utility function to use async functions as express handlers
Downloads
12
Readme
Express Async Handler
Utility function to use async functions as express handlers
yarn add @xpbytes/express-async-handlerimport { 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)
)