|
1 | 1 | # Koa vs Express
|
2 | 2 |
|
3 |
| - Philosophically, Koa aims to "fix and replace node", whereas Express "augments node". |
| 3 | + Philosophically, Koa aims to "fix and replace Node", whereas Express "augments Node". |
4 | 4 | Koa uses promises and async functions to rid apps of callback hell and simplify error handling.
|
5 |
| - It exposes its own `ctx.request` and `ctx.response` objects instead of node's `req` and `res` objects. |
| 5 | + It exposes its own `ctx.request` and `ctx.response` objects instead of Node's `req` and `res` objects. |
6 | 6 |
|
7 |
| - Express, on the other hand, augments node's `req` and `res` objects with additional properties and methods |
| 7 | + Express, on the other hand, augments Node's `req` and `res` objects with additional properties and methods |
8 | 8 | and includes many other "framework" features, such as routing and templating, which Koa does not.
|
9 | 9 |
|
10 |
| - Thus, Koa can be viewed as an abstraction of node.js's `http` modules, where as Express is an application framework for node.js. |
| 10 | + Thus, Koa can be viewed as an abstraction of Node.js's `http` modules, where as Express is an application framework for Node.js. |
11 | 11 |
|
12 | 12 | | Feature | Koa | Express | Connect |
|
13 | 13 | |------------------:|-----|---------|---------|
|
|
18 | 18 | | JSONP | | ✓ | |
|
19 | 19 |
|
20 | 20 |
|
21 |
| - 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. |
| 21 | + 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. |
22 | 22 | If you want to get rid of callbacks, use Koa.
|
23 | 23 |
|
24 |
| - 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. |
| 24 | + 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. |
25 | 25 |
|
26 | 26 | ## Does Koa replace Express?
|
27 | 27 |
|
|
34 | 34 | Typically many middleware would
|
35 | 35 | re-implement similar features, or even worse incorrectly implement them,
|
36 | 36 | when features like signed cookie secrets among others are typically application-specific,
|
37 |
| - not middleware specific. |
| 37 | + not middleware-specific. |
38 | 38 |
|
39 | 39 | ## Does Koa replace Connect?
|
40 | 40 |
|
|
75 | 75 |
|
76 | 76 | For example, instead of a "body parsing" middleware, you would instead use a body parsing function.
|
77 | 77 |
|
78 |
| -### Koa abstracts node's request/response |
| 78 | +### Koa abstracts Node's request/response |
79 | 79 |
|
80 | 80 | Less hackery.
|
81 | 81 |
|
82 | 82 | Better user experience.
|
83 | 83 |
|
84 | 84 | Proper stream handling.
|
85 |
| - |
| 85 | + |
86 | 86 | ### Koa routing (third party libraries support)
|
87 | 87 |
|
88 | 88 | Since Express comes with its own routing, but Koa does not have
|
89 |
| - any in-built routing, there are third party libraries available such as |
| 89 | + any built-in routing, there are third party libraries available such as |
90 | 90 | koa-router and koa-route.
|
91 | 91 | Similarly, just like we have helmet for security in Express, for Koa
|
92 | 92 | we have koa-helmet available and the list goes on for Koa available third
|
|
0 commit comments