From 9c2ea5a2a8d0e206d9d494baf1ce0d387a0c5f67 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Mon, 10 Mar 2014 04:20:54 -0700 Subject: [PATCH] Update koa-vs-express.md --- docs/koa-vs-express.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/koa-vs-express.md b/docs/koa-vs-express.md index 668157b..67029c2 100644 --- a/docs/koa-vs-express.md +++ b/docs/koa-vs-express.md @@ -1,11 +1,30 @@ THIS DOCUMENT IS IN PROGRESS. THIS PARAGRAPH SHALL BE REMOVED WHEN THIS DOCUMENT IS DONE. -TO DO: - -- Remove benchmark from readme - # Koa vs Express + Philosophically, Koa aims to "fix and replace node", whereas Express "augments node". + Koa uses co to rid apps of callback hell and simplify error handling. + It exposes its own `this.request` and `this.response` objects instead of node's `req` and `res` objects. + + Express, on the other hand, augments node's `req` and `res` objects with additional properties and methods + and includes many other "framework" features, such as routing and templating, which Koa does not. + + Thus, Koa can be viewed as an abstraction of node.js's `http` modules, where as Express is an application framework for node.js. + +| Feature | Koa | Express | Connect | +|------------------:|-----|---------|---------| +| Middleware Kernel | ✓ | ✓ | ✓ | +| Routing | | ✓ | | +| Templating | | ✓ | | +| Sending Files | | ✓ | | +| JSONP | | ✓ | | + + + Thus, if you'd like to be closer to node.js and traditional node.js-style coding, you probably want to stick to Connect/Express or similar frameworks. + If you want to dive into the land of generators, use Koa. + + As result of this different philosophy is that traditional node.js "middleware", i.e. functions of the form `(req, res, next)`, are incompatible with Koa. Your application will essentially have to be rewritten from the ground, up. + ## Does Koa replace Express? It's more like Connect, but a lot of the Express goodies