Koa 和 Express 4.0 有什么区别? [英] What are the differences between Koa and Express 4.0?

查看:17
本文介绍了Koa 和 Express 4.0 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Koa 和 Express 4.0 都是相当新的版本,据我所知,Koa 是由 Express 团队制作的.

Koa and Express 4.0 are both fairly new, and from what I've read, Koa was made by the Express team.

据我了解,Koa 需要 node 的特性,这些特性只在 node 的 0.11(不稳定分支)中可用,并且还使用了生成器.Express 4.0 似乎只是 Express 框架的下一个版本.

From what I understand, Koa requires features of node that are only available in 0.11 (the unstable branch) of node, and also uses generators. Express 4.0 seems to only be the next version of the Express framework.

有什么我完全遗漏的区别吗?Koa 和 Express 是否有可能(根据 Express 团队公开声明的内容)在未来某个时候合并?

Are there any differences I am missing completely? Is it likely (based on what the Express team has publicly stated) that Koa and Express will merge at some point in the future?

谢谢!

推荐答案

在发布开放式问题之前,搜索引擎应该是您的首选.

Search engines should be your first resort before posting open-ended questions.

来自 Koa 文档:

Koa 与 Express

从哲学上讲,Koa 的目标是修复和替换节点",而 Express 的目标是增强节点".Koa 使用 co 来摆脱应用程序的回调地狱并简化错误处理.它暴露了自己的 this.request 和this.response 对象而不是节点的 req 和 res 对象.

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 增加了节点的 req 和 res 对象附加属性和方法,并包括许多其他框架".Koa 没有的功能,例如路由和模板.

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.

因此,Koa 可以看作是对 node.js 的 http 模块的抽象,其中 Express 是 node.js 的应用程序框架.

Thus, Koa can be viewed as an abstraction of node.js's http modules, where as Express is an application framework for node.js.

...

Koa 会取代 Express 吗?

它更像是 Connect,但很多 Express 好东西都移到了Koa 中的中间件级别有助于形成更强大的基础.这使中间件更有趣,更不容易编写错误,因为整个堆栈,而不仅仅是最终应用程序代码.

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.

通常许多中间件会重新实现类似的功能,甚至更糟糕的是不正确地实现它们,当像签名 cookie 这样的功能时其他秘密通常是特定于应用程序的,而不是特定于中间件.

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.

...

为什么 Koa 不只是 Express 4.0?

Koa 与人们对 Express 的了解有很大不同,设计从根本上大不相同,因此从从 Express 3.0 到这个 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 和 Express 4.0 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆