
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Use generators for request handlers and middleware. Calls next only if there was an error. Useful for Express routes.
![NPM version][npm-badge] [npm-badge]: https://badge.fury.io/js/co-next.png
CoNext.js is a small function for JavaScript to wrap a generator
function with Co for use as request handlers and middlewares.
Calls the last argument (usually called next
) if there was an error, but not
if the generator finishes successfully. Useful with Express routes.
npm install co-next
CoNext.js follows semantic versioning, so feel free to
depend on its major version with something like >= 1.0.0 < 2
(a.k.a ^1.0.0
).
var next = require("co-next")
var app = require("express")()
app.get("/", next(function*(req, res, next) {
if (req.account == null) throw new Error("Unauthorized")
res.send("Hello, world!")
}))
In the above example, the thrown error will be passed to next
, which in
Express's case calls the error handling middleware later on. If the generator succeeds, the next
callback will not be called.
If you need to, like in middleware handlers, you can always call next
yourself:
app.use(next(function*(req, res, next) {
var account = yield accounts.read(req.session.accountId)
if (account == null) return void next(new Error("Unauthorized"))
req.account = account
next()
}))
CoNext.js is released under a Lesser GNU Affero General Public License, which in summary means:
For more convoluted language, see the LICENSE
file.
Andri Möll typed this and the code.
Monday Calendar supported the engineering work.
If you find CoNext.js needs improving, please don't hesitate to type to me now at andri@dot.ee or create an issue online.
1.0.0 (Jan 31, 2015)
FAQs
Use generators for request handlers and middleware. Calls next only if there was an error. Useful for Express routes.
The npm package co-next receives a total of 42 weekly downloads. As such, co-next popularity was classified as not popular.
We found that co-next demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.