express-async-await
Use async/await in your routes without
polluting / wrapping them.Usage
Pass the app to the library and we'll monkey-patch it for you:const aa = require('express-async-await')
const app = aa(express())
app.get('/ok', async function(req, res, next) {
res.json({hello: 'world'})
})
app.get('/no', async function(req, res) {
res.notSomethingICanRun({hello: 'world'})
})
app.use((err, req, res, next) => {
console.error(err)
res.status(500).send("Ouch!")
})
Now
app.$method(route, fn)
support async functions out of the box!(have a look at the example app)
Installation
npm i express-async-await
npm add express-async-await