为什么以及何时使用 Node.js?
可能的重复:
如何决定何时使用 Node.js?
抱歉,如果我'我有点模棱两可,但我试图了解使用 Node.js 而不是其他服务器端语言。
我是一名 JavaScript 爱好者,所以我可能会使用 Node.js,但我想知道是否应该在我的项目中使用它。
Possible Duplicate:
How to decide when to use Node.js?
Sorry if I'm a bit ambiguous, but I'm trying to understand the real advantages of using Node.js instead of other server-side language.
I'm a JavaScript enthusiast, so I'm probably going to play with Node.js, but I want to know if I should use it in my projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它的事件异步非阻塞 I/O 构建在 V8。
因此,我们拥有 V8(即 Google JavaScript 解释器)的所有性能增益。由于 JavaScript 性能竞赛尚未结束,您可以期待 Google 不断更新 V8 的性能(免费)。
我们有非阻塞 I/O,这就是执行 I/O 的正确方法。这基于事件循环并为 I/O 使用异步回调。
它为您提供了有用的工具,例如创建 HTTP 服务器、创建 TCP 服务器、处理文件 I/O。
它是一个低级高性能平台,可以执行任何类型的 I/O,而无需从头开始用 C 语言编写整个内容。由于非阻塞 I/O,它的扩展性非常好。
因此,如果您想使用非阻塞 I/O 编写高度可扩展且高效的应用程序,同时仍然拥有可用的高级脚本语言,那么您需要使用 Node.js。如果需要,您可以通过用 C 编写扩展来手动优化部分代码。Node.js
有很多操作系统库可以为您提供抽象,例如 Express.js 和现在。
如果您希望(缓慢的)高级抽象为您完成所有事情,那么您就不想使用 Node.js。如果您想要 RAD,您就不想使用 Node.js。如果您无法信任一个年轻的平台,那么您就不想使用 Node.js,这要么是因为必须自己编写大量代码来执行构建到其他框架中的操作,要么是因为您无法使用 Node .js,因为 API 尚未稳定或者它是 1.0 版本。
It's evented asynchronous non-blocking I/O build ontop of V8.
So we have all the performance gain of V8 which is the Google JavaScript interpreter. Since the JavaScript performance race hasn't ended yet, you can expect Google to constantly update performance on V8 (for free).
We have non-blocking I/O which is simply the correct way to do I/O. This is based on an event loop and using asynchronous callbacks for your I/O.
It gives you useful tools like creating a HTTP server, creating a TCP server, handling file I/O.
It's a low level highly performant platform for doing any kind of I/O without having to write the entire thing in C from scratch. And it scales very well due to the non-blocking I/O.
So you want to use Node.js if you want to write highly scaling and efficient applications using non-blocking I/O whilst still having a high level scripting language available. If needed, you can hand optimise parts of your code by writing extensions in C.
There are plenty of OS libraries for Node.js that will give you abstractions, like Express.js and now.
You don't want to use Node.js if you want (slow) high level abstractions to do everything for you. You don't want to use Node.js if you want RAD. You don't want to use Node.js if you can't afford to trust a young platform, either due to having to write large pieces of code yourself to do things that are build into other frameworks or because you can't use Node.js, because the API isn't stable yet or it's a sub 1.0 release.
最常被引用的两个优点是:
但对我来说,最有趣的部分是该领域发生的活动数量。 Node 有很多非常有趣的想法正在开发中 - 请务必查看 Node.js 模块列表。
The two most oft-quoted advantages are:
For me though, the most interesting part is the amount of activity happening in this area. There are a lot of very interesting ideas under development for node - be sure to check out the list of Node.js modules.
当您是(或者即使不是)JavaScript 爱好者时,您可以/应该使用 Node.js,原因有很多:
When you're (or even if you are not) a JavaScript enthusiast you can/should use Node.js for a number of reasons:
就我个人而言,我最有可能在以下情况下使用 Node.js:
Personally, I'd most likely use Node.js when: