Skip to content

Compose an array of middleware into a single function for use in Express, Connect, router, etc

License

Notifications You must be signed in to change notification settings

blakeembrey/compose-middleware

Repository files navigation

Compose Middleware

NPM version NPM downloads Build status Test coverage

Compose an array of middleware into a single function for use in Express, Connect, router, etc.

Installation

npm install compose-middleware --save

Usage

Compose multiple middleware functions into a single request middleware handler, with support for inline error handling middleware.

var express = require("express");
var compose = require("compose-middleware").compose;

var app = express();

app.use(
  compose([
    function(req, res, next) {},
    function(err, req, res, next) {},
    function(req, res, next) {}
  ])
);

P.S. The composed function takes three arguments. Express.js (and Connect, router) only accept error handlers of four arguments. If you want to return an error handler from compose instead, try the errors export - it works exactly the same, but exposes the four argument middleware pattern.

License

MIT

About

Compose an array of middleware into a single function for use in Express, Connect, router, etc

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •