pype
Middleware-style piping for server or browser. No dependencies. Works with async. WIP - not suitable for production.
use cases
- Clean control flow
- Centralized error handling
- Testing a middleware stack without a server running
- or when you just don't feel like using express but you reeally like piping stuff
install
$ npm install pype-stack
usage
// in browser or node w/o servervar pype = { reqfoo = 1; return ; } { reqfoo++; return ; } { console; } { console; } stack = one two finalHandler;// run; // logs {foo: 2} // in node w servervar http = server = http;server;server; // curried in browser w subsequent multiple calls - assume valid functionsvar login = ;;
arguments
req res;
context
[any] value for this
for each fn
stack
[array] of middleware
errorHandler
[function] [optional] if called stops execution of the stack. Is passed the error.
finalHandler
[function] [optional] last fn to run. Useful in test settings.
req
, res
[objects] [optional]
Note: All middleware use express-style args req, res, next
. The exceptions are errorHandler
and finalHandler
. errorHandler
is unlike express a separate arg from the stack and only called w err, req, res
. finalHandler
is called w req, res
. Empty objects are passed to return fn as default.
test
$ npm test
todos
- more tests
licence
MIT