https://github.com/parro-it/comws
koa-like generator middlewares for any apps (not just webserver!)
https://github.com/parro-it/comws
Last synced: 9 months ago
JSON representation
koa-like generator middlewares for any apps (not just webserver!)
- Host: GitHub
- URL: https://github.com/parro-it/comws
- Owner: parro-it
- License: mit
- Created: 2015-03-11T14:39:59.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T09:18:26.000Z (over 5 years ago)
- Last Synced: 2025-04-26T09:38:38.974Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 102 KB
- Stars: 20
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# comws
[](https://greenkeeper.io/)
> Expressive middleware for node.js using generators via [co](https://github.com/visionmedia/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.
[](http://travis-ci.org/parro-it/comws)
[](https://npmjs.org/package/comws)
[](https://npmjs.org/package/comws)
# Installation
```bash
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
```js
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:
```js
const CoMws = require('comws');
const {mw1, mw2} = require('middlewares');
const mws = new CoMws();
mws.use(mw1, mw2);
```
or also chain `use` calls:
```js
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