http-middleware

1.0.5 • Public • Published

http-middleware

NPM version build status Test coverage Downloads js-standard-style

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.

See Also

License

MIT

Package Sidebar

Install

npm i http-middleware

Weekly Downloads

25

Version

1.0.5

License

MIT

Last publish

Collaborators

  • yoshuawuyts