Cottage is the fastest, simple, and intuitive server framework built on Koa.js.
- Fastest Framework on Node - See performance
- 100% Koa.js compatible - You can use all plugins and modules of koa.
- Simple code - Aren't you tired using
res.sendorthis.body? Why can't we justreturnthe response? - Additional Sugar Features
$ npm install --save cottage
Cottage requires iojs or Node v4.0.0 or higher.
To use it with Node v0.12, you must run node with the --harmony flag.
const cottage = require('cottage');
const app = cottage();
app.get('/hello', function*(req, res) {
let hello = yield asyncHello();
return hello; // just return data
});
// 100% fully compatible with koa
app.use(koaMiddleware());
// because cottage is built on the top of Koa.
koa().use(app.callback()).listen(8080);
// simple shorthand without importing koa.
app.listen(8080);Benchmark have been ran on Intel Xeon E3-1250v3 @ 3.50ghz with Node.js 6.1.0 single instance. Tested from Github API sample using wrk
| Framework | Mean Throughput (req/sec) | Stddev |
|---|---|---|
| [email protected] | 15130.12 | 142.45 |
| [email protected] | 11455.67 | 201.95 |
| [email protected] | 12279.01 | 157.33 |
| [email protected] | 2402.31 | 53.14 |
As the benchmark result shows, cottage is the fastest framework in Node.js.
Cottage uses Radix Tree for URL routing, which is faster than any other data structures. Also, cottage uses technique called "middleware precomposition", which precomposes middleware only at first time, not the every runtime.
You can write down a code just as you've done on the Express, but using generator-based flow control instead of dirty callback hell.
NOTE THAT It may look exactly like Express handler, but it's very different:
function* (req, res, next) { }reqiskoa.Requestresiskoa.Responsenextis aGeneratorthat points next middlewaresthisiskoa.Context
- API Documentation (Currently Working)
- Samples (Currently Working)