Skip to content

floatdrop/express-generators

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-generators Build Status

Use generators with Express.

Installation

npm install express-generators

Usage

const express = require('express');
const expressGenerators = require('express-generators')(express);
const got = require('got');

const app = expressGenerators();

app.use('/callback', function (req, res, next) {
    got('google.com').then(r => {
        req.google = r;
        next();
    }, next);
});

app.use('/generator', function * (req, res) {
    req.google = yield got('google.com');
});

app.get('*', function * (req, res) {
    res.send(req.google.body);
});

app.listen(8000);

API

expressGenerators(express)

Returns patched Express constructor with patched Router class.

Following methods are wrapped to support generators:

  • app.get, app.post and other methods from methods package
  • app.use
  • app.param
  • app.route
  • app.all
  • app.del

Notes

Rather than using the next() method, express-generators detects if you have written to the response.

License

MIT © Vsevolod Strukchinsky

About

Use generators with express

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%