什么是Node.js? [关闭]

本文翻译自:What is Node.js? [closed]

I don't fully get what Node.js is all about. 我没有完全了解Node.js的全部内容。 Maybe it's because I am mainly a web based business application developer. 也许是因为我主要是一个基于Web的业务应用程序开发人员。 What is it and what is the use of it? 它是什么以及它的用途是什么?

My understanding so far is that: 到目前为止,我的理解是:

  1. The programming model is event driven, especially the way it handles I/O . 编程模型是事件驱动的,尤其是它处理I / O的方式
  2. It uses JavaScript and the parser is V8 . 它使用JavaScript ,解析器是V8
  3. It can be easily used to create concurrent server applications. 它可以很容易地用于创建并发服务器应用程序。

Are my understandings correct? 我的理解是否正确? If yes, then what are the benefits of evented I/O, is it just more for the concurrency stuff? 如果是,那么即使I / O有什么好处,它对于并发性的东西更多吗? Also, is the direction of Node.js to become a framework like, JavaScript based (V8 based) programming model? 另外,Node.js的方向是成为一个类似于基于JavaScript(V8的)编程模型的框架吗?


#1楼

参考:https://stackoom.com/question/7uIm/什么是Node-js-关闭


#2楼

Well, I understand that 好吧, 我明白了

  • Node's goal is to provide an easy way to build scalable network programs. Node的目标是提供一种简单的方法来构建可扩展的网络程序。
  • Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted. Node在设计上类似于Ruby的Event Machine或Python的Twisted等系统。
  • Evented I/O for V8 javascript. 针对V8 javascript的求偶I / O.

For me that means that you were correct in all three assumptions. 对我而言,这意味着你在所有三个假设中都是正确的。 The library sure looks promising! 图书馆看起来很有前途!


#3楼

V8 is an implementation of JavaScript. V8是JavaScript的一个实现。 It lets you run standalone JavaScript applications (among other things). 它允许您运行独立的JavaScript应用程序(以及其他内容)。

Node.js is simply a library written for V8 which does evented I/O. Node.js只是为V8编写的库,它实现了I / O. This concept is a bit trickier to explain, and I'm sure someone will answer with a better explanation than I... The gist is that rather than doing some input or output and waiting for it to happen, you just don't wait for it to finish. 这个概念有点难以解释,我确信有人会回答比我更好的解释...要点是,不要做一些输入或输出并等待它发生,你只是不要等待为了它完成。 So for example, ask for the last edited time of a file: 例如,请求文件的最后编辑时间:

// Pseudo code
stat( 'somefile' )

That might take a couple of milliseconds, or it might take seconds. 这可能需要几毫秒,或者可能需要几秒钟。 With evented I/O you simply fire off the request and instead of waiting around you attach a callback that gets run when the request finishes: 使用事件I / O,您只需触发请求,而不是等待您附加一个在请求完成时运行的回调:

// Pseudo code
stat( 'somefile', function( result ) {
  // Use the result here
} );
// ...more code here

This makes it a lot like JavaScript code in the browser (for example, with Ajax style functionality). 这使它很像浏览器中的JavaScript代码(例如,具有Ajax样式功能)。

For more information, you should check out the article Node.js is genuinely exciting which was my introduction to the library/platform... I found it quite good. 有关更多信息,您应该查看文章Node.js真正令人兴奋 ,这是我对库/平台的介绍...我发现它非常好。


#4楼

I think the advantages are: 我认为其优点是:

  1. Web development in a dynamic language (JavaScript) on a VM that is incredibly fast (V8). 在VM上以动态语言(JavaScript)进行Web开发,速度非常快(V8)。 It is much faster than Ruby, Python, or Perl. 它比Ruby,Python或Perl快得多。

  2. Ability to handle thousands of concurrent connections with minimal overhead on a single process. 能够以最小的单个进程开销处理数千个并发连接。

  3. JavaScript is perfect for event loops with first class function objects and closures. JavaScript非常适合具有第一类函数对象和闭包的事件循环。 People already know how to use it this way having used it in the browser to respond to user initiated events. 人们已经知道如何使用它在浏览器中使用它来响应用户发起的事件。

  4. A lot of people already know JavaScript, even people who do not claim to be programmers. 很多人已经了解JavaScript,甚至是那些自称不是程序员的人。 It is arguably the most popular programming language. 它可以说是最流行的编程语言。

  5. Using JavaScript on a web server as well as the browser reduces the impedance mismatch between the two programming environments which can communicate data structures via JSON that work the same on both sides of the equation. 在Web服务器和浏览器上使用JavaScript可以减少两个编程环境之间的阻抗不匹配,这两个编程环境可以通过JSON传递数据结构,这两个方程在方程式的两侧都是相同的。 Duplicate form validation code can be shared between server and client, etc. 可以在服务器和客户端等之间共享重复的表单验证代码。


#5楼

The closures are a way to execute code in the context it was created in. 闭包是一种在创建它的上下文中执行代码的方法。

What this means for concurency is that you can define variables, then initiate a nonblocking I/O function, and send it an anonymous function for its callback. 这意味着你可以定义变量,然后启动非阻塞I / O函数,并为其回调发送一个匿名函数。

When the task is complete, the callback function will execute in the context with the variables, this is the closure. 当任务完成后,回调函数将在带有变量的上下文中执行,这就是闭包。

The reason closures are so good for writing applications with nonblocking I/O is that it's very easy to manage the context of functions executing asynchronously. 闭包非常适合编写具有非阻塞I / O的应用程序,因为管理异步执行的函数的上下文非常容易。


#6楼

Node.js is an open source command line tool built for the server side JavaScript code. Node.js是一个为服务器端JavaScript代码构建的开源命令行工具。 You can download a tarball , compile and install the source. 您可以下载tarball ,编译并安装源代码。 It lets you run JavaScript programs. 它允许您运行JavaScript程序。

The JavaScript is executed by the V8 , a JavaScript engine developed by Google which is used in Chrome browser. JavaScript由V8执行, V8是由Google开发的JavaScript引擎,用于Chrome浏览器。 It uses a JavaScript API to access the network and file system. 它使用JavaScript API来访问网络和文件系统。

It is popular for its performance and the ability to perform parallel operations. 它的性能和执行并行操作的能力很受欢迎。

Understanding node.js is the best explanation of node.js I have found so far. 理解node.js是我到目前为止找到的node.js的最佳解释。

Following are some good articles on the topic. 以下是关于该主题的一些好文章。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章