A stack/array of Express style middleware.
$ npm install --save mwstack
const app = require('express')()
const {Stack} = require('mwstack')
// Create a stack with some middleware
const stack = new Stack()
.use(function (req, res, next) {
// do stuff
next()
}, function (req, res) {
// do other stuff
// send response
res.send()
})
.error(function (err, req, res, next) {
// handle errors
next()
})
// Hook into express
app.use(stack)
Create a new stack. A stack is an array like object with a few additional methods.
Add middleware to the stack. Middleware are added in order and arrays are not flattened.
Add error middleware to the stack. Error middleware are added in order and arrays are not flattened.
Add normal middleware or error middleware to the stack, infer they type based on the arity of the function (0-3 args is normal, 4 args is error). This behavior is the legacy behavior Express used to infer the middleware type.
Create a new flat stack. These are the same as Stack
except arrays of middleware are flattened when added.
Returns true
when the middleware was added to a stack as an error middleware.
A symbol
used internally to label middleware functions as errors.