A better way to use Express.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.eslintignore
.eslintrc
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

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