什麼是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. 以下是關於該主題的一些好文章。

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