WELCOME TO SCALABILITI
We're a UK Collective, doing our bit to help increase that distribution, by bringing the future that already exists to a wider audience.

Crunch, save time, save tax, save money
London Tech Jobs at Career 2.0

Koa Seeks to answers some of Nodejs challenges

The fervent apostles Nodejs have been very loud promoting server-side JavaScript. And indeed it is light weight, and fast/responsive by avoiding thread blocking by having callbacks passed as the last argument.

However beyond demos when writing 'real' applications you quickly end up indented off the right hand margin. In a sane light there is a huge challenge in readability and maintainability of nodejs applications.

There is also an incredibly active community, including Koa is an expressive middleware for node.js using generators to make web applications and APIs more enjoyable to write and read.

An example: the app.callback method returns a handler that is compatible with Node’s http.createServer method, and uses co:

app.callback = function(){
  var mw = [respond].concat(this.middleware);
  var gen = compose(mw);
  var fn = co(gen);
  var self = this;
 
  return function(req, res){
    var ctx = self.createContext(req, res);
    onSocketError(ctx, ctx.onerror);
    fn.call(ctx, ctx.onerror);
  }
};

This example is from Koa’s source, and allows the following to work:

var koa = require('koa');
var app = koa();
app.listen(3000);
 
// Equivalent: http.createServer(app.callback()).listen(3000);