Socket
Book a DemoInstallSign in
Socket

http-middleware

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-middleware

Middleware layer for http

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

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

  • http-framework

License

MIT

Keywords

middleware

FAQs

Package last updated on 20 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts