package
Simple asynchronous middleware pattern
npm install throwbackGitHub-flavored package documentation.
Across all versions, last 30 days.
1,595,536 in 30 days
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
26.2 kB
Includes dependencies.
Simple asynchronous middleware pattern.
npm install throwback --saveCompose asynchronous (promise-returning) functions.
const { compose } = require("throwback");
const fn = compose([
async function(ctx, next) {
console.log(1);
try {
await next();
} catch (err) {
console.log("throwback", err);
}
console.log(4);
},
async function(ctx, next) {
console.log(2);
return next();
}
]);
Tip: In development (NODE_ENV !== "production"), compose will throw errors when you do something unexpected. In production, the faster non-error code paths are used.
Build a micro HTTP server!
const { createServer } = require("http");
const finalhandler = require("finalhandler"); // Example only, not compatible with single `ctx` arg.
const { compose } = require("throwback");
const app = compose([
function({ req, res }, next) {
res.end("Hello world!");
}
]);
createServer(function(req, res) {
return app({ req, res }, finalhandler());
}).listen(3000);Built for servie and inspired by koa-compose.
MIT