https://github.com/tur-nr/node-mware
Create middleware stacks.
https://github.com/tur-nr/node-mware
Last synced: 2 months ago
JSON representation
Create middleware stacks.
- Host: GitHub
- URL: https://github.com/tur-nr/node-mware
- Owner: tur-nr
- License: mit
- Created: 2014-10-03T22:21:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-29T17:03:36.000Z (over 8 years ago)
- Last Synced: 2025-04-11T08:21:54.547Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 47.9 KB
- Stars: 22
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mware
[](https://travis-ci.org/tur-nr/node-mware) [](https://coveralls.io/github/tur-nr/node-mware?branch=master)
`mware` 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).
### Usage
```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');
});
```## 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.## Async/await
For an async/await approach see [`mware-async`](https://github.com/9technology/mware-async).
## License
[MIT](LICENSE)
Copyright (c) 2016 [Christopher Turner](https://github.com/tur-nr)