http-middleware
v1.0.5
Published
Middleware layer for http
Downloads
56
Maintainers
Readme
http-middleware
Middleware layer for http
.
Installation
$ npm install http-middleware
Usage
const mw = require('http-middleware')
const http = require('http')
http.createServer((req, res) => {
const fns = [
(req, res) => res.write('oh yeah!'),
(req, res, next) => {
res.statusCode = 200
next()
}
]
mw(req, res, fns, res.end)
}).listen(1337)
API
mw(req, res, middleware [,done])
Create a middleware layer that runs an array of middleware functions in
sequence. Middleware functions have a signature of req, res, next
where
next
is optional.
FAQ
What is middleware?
Middleware is typically an array of functions that is run before executing 'business logic'. Function types include authentication, rate limiting, logging and more.
Why not use a framework for middleware?
Frameworks are a bundle of opinions. By splitting features off into separate modules (like this middleware module) users can compose their perfect framework. See http-framework for more modules in this spirit.