p-connect
WIP - nothing to see here
Last updated 5 months ago by bret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install p-connect 
SYNC missed versions from official npm registry.

p-connect

Converts connect style middleware, routes, errorRoutes to a promise. Also supports http-hash-route style routes.

npm install p-connect

Usage

const { pMiddleware, route } = require('p-connect')
const bodyParser = require('body-parser')
const pJson = pMiddleware(bodyParser.json())

const asyncRoute = async (req, res) => {
   await pJson(req, res)
   // req.body is now populated
}

app.use(route(asyncRoute))

API

pMiddleware(connectMiddleware)

Convert a callback style middleware to work inside of an asynchronous environment. Does not return any value, it will just throw if an error occures inside the middleware.

route(asyncConnectRoute)

Converts an async connect route to a callback connect route.

connectRoute(req, res, next) should return a promise. route(connectRoute) = (req, res, next) => {...} returns a connect style callback middleware that calls next(err) when asyncConnectRoute throws. You should still call the next callback in async middleware if you want to keep the middleware chain moving.

License

MIT

Current Tags

  • 2.0.0                                ...           latest (5 months ago)

4 Versions

  • 2.0.0                                ...           5 months ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |