1.3.0 • Published 6 years ago
@i2/async-express v1.3.0
async-express
Run async/await express middlewares or routes.
Install
npm install --save async-express
Usage
const asyncExpress = require('async-express');
const express = require('express');
const app = express();
asyncExpress(app);
// you can use generators, they are wrapped using `co`
app.getAsync('/index', function * (req, res) {
const videos = yield model.all();
res.send(video);
});
// you can use a function that return a promise
app.getAsync('/index', (req, res) => {
return model.all().then(videos => {
res.send(video);
});
});
// you can use async/await
app.getAsync('/index', async (req, res) => {
const videos = await model.all();
res.send(video);
});
// and the same for middlewares
app.use(async (req, res, next) => {
req.user = await model.findUser();
next();
}
License
UNLICENSED © Andrea Parodi