README
comws
Expressive middleware for node.js using generators via co to make node applications more enjoyable to write. Comws middleware flow in a stack-like manner exactly like koa ones. Use of generators also greatly increases the readability and robustness of your application.
Installation
npm install comws --save
Comws is supported in all versions of node > 4.
Getting started
See all examples in example folder to get started.
Open an issue if you have any question or suggestion.
Example
const CoMws = require('comws');
const mws = new CoMws();
mws.use(function *(next){
this.result += ' hello';
yield next();
});
mws.use(function *(next){
this.result += ' world';
yield next();
});
const ctx = {result: 'yet another'};
mws.run(ctx).then(function() {
//ctx.result === 'yet another hello world'
});
Use multiple middlewares
Starting from version 2.1, you can also
use multiple middleware in the same use
call:
const CoMws = require('comws');
const {mw1, mw2} = require('middlewares');
const mws = new CoMws();
mws.use(mw1, mw2);
or also chain use
calls:
const CoMws = require('comws');
const {mw1, mw2} = require('middlewares');
const mws = new CoMws();
mws.use(mw1).use(mw2);
Running tests
$ npm install && npm test
License
The MIT License (MIT)
Copyright (c) 2016 parro-it