async-express
Simple middleware wrapper to make Express handlers async compatible.
Usage
npm install --save async-express
In a route
const express = require('express');
const _async = require('async-express');
const app = express();
app.get('/', _async((req, res, next) => {
await new Promise(r => setTimeout(r, 5000));
req.send('Waited 5 seconds successfully');
}));
The sample above can be refactored using decorator syntax as the following
const express = require('express');
const _async = require('async-express');
const app = express();
app.get('/', waitForABit);
@_async
function waitForABit(req, res, next) {
await new Promise(r => setTimeout(r, 5000));
req.send('Waited 5 seconds successfully');
}