🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

caco-express

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caco-express

Express middleware wrapper using caco generator function

1.0.0
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 11 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts