Middleware Chain
Chain your node.js functions.
Middleware Chain allows you to simply chain your syncronous / asyncronous middleware functions. It works in a very similar way to how express handles middleware.
Works really well using the consign module to autoload your scripts.
Usage
chain([context], chain);
var chain = ; ; // Optionally pass in contextvar app = hello: 'world' ;;
Please check out the examples or test folder for more!
Installation
$ npm install middleware-chain
Features
- Chain functions / middleware
- Works with both asyncronous and syncronous functions
- Brings structure to scripts with a lot of callbacks
- Allows modifiable flow
- Ability to pass in initial context
- Chains are nestable
- Ability for parrallel chains
- Test driven
- Fast, Light-weight with no external dependencies
Context parameter
The optional context object is passed in as the first parameter, it can be an object containing anything you'd like to access throughout your middleware chain.
Chain parameter
The chain parameter is required, it's an array containing functions to be called in order.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install$ npm test
Full Example
var chain = ; { ;} { ;} { ;} ;
Output
Hello from oneHello from twoHello from three