node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »

express-next

express-next

NPM version Dependency Status Travis CI Coveralls

A modern way for using Express.

This package adds the following feature(s) to Express:

Environment Requirement

  • node >= 0.12 with --harmony
  • iojs >= 1.0.0
  • Express >= 4.5 (only this version tested, should work for 4.x)

Usage

npm install --save express express-next
const express = require('express-next')
const app = express()
const router = express.Router()
 
// Normal function works as usual 
app.get('/', function (req, res) {
  res.render('index')
})
 
app.use('/users', router)
 
// Generator function works as well 
router.get('/:id', function* (req, res) {
  let user = yield User.find(req.params.id)
 
  if (user) {
    res.locals.user = user
    res.render('user')
  } else {
    // Equals to "next(new Error(`User ${req.params.id} not found!`))" 
    throw new Error(`User ${req.params.id} not found!`)
  }
})

Contributors

Via GitHub