为什么以及何时使用 Node.js?

发布于 2024-10-31 19:09:33 字数 363 浏览 0 评论 0原文

可能的重复:
如何决定何时使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

厌倦 2024-11-07 19:09:33

它的事件异步非阻塞 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.

老旧海报 2024-11-07 19:09:33

最常被引用的两个优点是:

  • JavaScript 既是服务器端又是客户端。需要学习的东西更少,上下文切换更少,并且能够在两端重用代码。
  • 使用非阻塞 I/O 和 Chrome 的 V8 引擎,提供快速、高度可扩展的服务器。

但对我来说,最有趣的部分是该领域发生的活动数量。 Node 有很多非常有趣的想法正在开发中 - 请务必查看 Node.js 模块列表

The two most oft-quoted advantages are:

  • JavaScript is both server-side and client-side. There are fewer things to learn, less context switching, and the ability to reuse code across the two sides.
  • Uses non-blocking I/O, and Chrome's V8 engine, to provide fast, highly scalable servers.

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.

-柠檬树下少年和吉他 2024-11-07 19:09:33

当您是(或者即使不是)JavaScript 爱好者时,您可以/应该使用 Node.js,原因有很多:

  • 它是一个低级、轻量级且独立的框架,它将 JavaScript 的强大功能带入服务器端环境。
  • 如果您喜欢更高级别的抽象,那么有大量的 模块npm 包管理器,您可以在其中找到各种即用型应用程序。
  • 快速/无阻碍的开发过程 - 例如,您不需要大量额外的工具来开始编写严肃的东西。
  • 基于开源的大型社区,充满了爱好者和非常有才华的人。
  • 专为创建面向实时 Web 的应用程序而设计 - 这就是(不久的)未来。

When you're (or even if you are not) a JavaScript enthusiast you can/should use Node.js for a number of reasons:

  • It's a low-level, lightweight and standalone framework which brings power of JavaScript to the server-side environment.
  • If you like more higher level abstraction then there is a large number of modules and the npm package manager where you can find wide range of ready-to-use applications.
  • Fast/unencumbered development process - for example, you don't need tons of additional tools in order to start writing serious stuff.
  • Big open source based community full of enthusiasts and very talented people.
  • Made for creating real-time web oriented applications - that's where the (near) future is.
指尖上得阳光 2024-11-07 19:09:33

就我个人而言,我最有可能在以下情况下使用 Node.js:

  • 我想编写一个不使用 的服务器HTTP 协议
  • 我正在制作服务器实现的原型。
  • 我正在编写一个不需要大量流量的服务器(尽管我从未在匹配的 C++ 实现旁边分析过 Node.js 实现)。
  • 我想积极参与社区(该社区显然增长得相当快)。

Personally, I'd most likely use Node.js when:

  • I want to write a server that doesn't use the HTTP protocol.
  • I'm prototyping a server implementation.
  • I'm writing a server that isn't expecting a ton of traffic (although I've never profiled a Node.js implementation next to, say, a matching C++ implementation).
  • I want to get active in the community (which is apparently growing quite rapidly).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文