1.3.0 • Published 6 years ago

@i2/async-express v1.3.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
6 years ago

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

1.3.0

6 years ago

1.2.0

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.0.1

7 years ago