caco-express

1.0.0 • Public • Published

caco-express

Express middleware wrapper for caco generator function.

Build Status

npm install caco-express

This is a caco version of co-express, which supports 'yielding' callback functions using next(err, val).

Calling next() without argument, passes control to the next middleware stack.

var express = require('express')
var wrap = require('caco-express')
var fs = require('fs')
 
var app = express()
 
app.get('/foo', wrap(function * (req, res, next) {
  // yield callback function using caco next(err, val)
  req.data = yield fs.readFile('./data.json', 'utf8', next)
  yield setTimeout(next, 10)
 
  next() // calling next() passes to next middleware
}, function * (req, res) {
  res.send(data)
}))
 
// 4 arguments for error handling middleware
app.use(wrap(function * (err, req, res, next) {
  res.status(500).send({ 
    success: false, 
    message: err.message 
  })
}))

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i caco-express

Weekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • cshum