What are the differences between Koa and Express 4.0?
Koa和Express 4.0都是相当新的东西,据我所读,Koa是由Express团队生产的。
据我了解,Koa要求节点的功能仅在节点的0.11(不稳定分支)中可用,并且还使用生成器。 Express 4.0似乎只是Express框架的下一个版本。
我完全想念有什么区别吗? (根据Express团队公开声明的内容)Koa和Express将来可能会合并吗?
谢谢!
在发布开放式问题之前,搜索引擎应该是您的第一选择。
来自Koa文档:
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.
...
Does Koa replace Express?
It's more like Connect, but a lot of the Express goodies were moved to
the middleware level in Koa to help form a stronger foundation. This
makes middleware more enjoyable and less error-prone to write, for the
entire stack, not just the end application code.Typically many middleware would re-implement similar features, or even
worse incorrectly implement them, when features like signed cookie
secrets among others are typically application-specific, not
middleware specific.
...
Why isn't Koa just Express 4.0?
Koa is a pretty large departure from what people know about Express,
the design is fundamentally much different, so the migration from
Express 3.0 to this Express 4.0 would effectively mean rewriting the
entire application, so we thought it would be more appropriate to
create a new library.
- 在快递服务中,Koa不提供诸如路由,模板化,发送文件和JSONP之类的功能。
- koa公开了自己的ctx.request和ctx.response对象,而不是node的req和res对象,即,形式(req,res,next)的函数与Koa不兼容。
- Koa可以看作是node.js的http模块的抽象,而Express是Node.js的应用程序框架。
有关详细答案,您可以访问此链接上的官方文档:
https://github.com/koajs/koa/blob/master/docs/koa-vs-express.md