Nightly Perpetrated Mischief
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

mware

1.0.1 • Public • Published

mware

mware is a utility for creating a middleware stack with any node or browser application. Inspired by the middleware pattern in connect.

Build Status Coverage Status

Usage

import mware from 'mware';
const { use, run } = mware();
 
// add middleware
use((ctx, next) => {
    console.assert(ctx === context);
 
    return next();                     // next middleware
    return next(null, true);           // stop the stack
    return next(new Error('oopsies')); // stop and report error
});
 
// run stack
const context = {};
run([context], (err) => {
    if (err) throw err;
    console.log('stack complete');
});

Installation

NPM

npm install --save mware

Yarn

yarn add mware

API

mware()

Returns a mware instance.

Instance

#use(fn...)
  • fn: Function|[]Function, Middleware functions to add to stack.
#run([args], [done])
  • args: []*, List of arguments to pass to each middleware function.
  • done: Function, Callback for when the middleware stack has stopped.

License

MIT

Copyright (c) 2016 Christopher Turner

install

npm i mware

Downloadsweekly downloads

306

version

1.0.1

license

MIT

repository

githubgithub

last publish

collaborators

  • avatar