mware
Version:
Create middleware stacks.
63 lines (42 loc) • 1.45 kB
Markdown
is a utility for creating a middleware stack with any node or browser application. Inspired by the middleware pattern in [connect](https://github.com/senchalabs/connect).
[](https://travis-ci.org/tur-nr/node-mware) [](https://coveralls.io/github/tur-nr/node-mware?branch=master)
```js
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');
});
```
```
npm install --save mware
```
```
yarn add mware
```
Returns a `mware` instance.
* `fn: Function|[]Function`, Middleware functions to add to stack.
* `args: []*`, List of arguments to pass to each middleware function.
* `done: Function`, Callback for when the middleware stack has stopped.
[ ](LICENSE)
Copyright (c) 2016 [Christopher Turner](https://github.com/tur-nr)
`mware`