Recently I have been studying Node

I will absorb and organize what I have learned from it into this note for future reference

This is the first article in this series, an introduction to Node

This article will answer a few questions

  1. When was Node born?
  2. Who created it?
  3. Why is it called Node?
  4. Why is JavaScript the implementation language of Node?
  5. What are the main features of Node?
  6. What are the application scenarios of Node?
  7. What challenges do CPU intensive applications bring to Node, and how can they be solved?

1. When was Node born?

Node was born in 2009

In March 2009, the author of Node announced on his blog that he was going to create a lightweight Web server based on V8 and provide a set of libraries

The initial version was released on GitHub in May of that year

In July 2011, a Windows version was released with Microsoft support

2. Who created it?

Ryan Dahl was the creator of Node and is known as the Father of Node

But in January 2012, Ryan Dahl handed over the REINS to Isaac Z.Schlueter, the author of the later NPM, to work on Node releases and bug fixes

3. Why is it called Node?

Nodejs is called Nodejs, Nodejs, node.js, etc.

Ryan Dahl originally called his project Web.js, a Web server, but the project expanded beyond his original vision of a web server. As a basic framework for building web applications, you can build more things on top of it, such as servers, clients, command-line tools, and so on. Node is developed as a single-threaded, single-process system that forces no sharing of any resources. It contains network-friendly libraries and provides the infrastructure for building large distributed applications. Its goal is also called a fast and scalable network application service. It is very simple on its own, organizing many nodes through communication protocols, and it is very easy to scale to build large network applications. Each Node process constitutes a Node in the network application, which is exactly what Node is

4. Why is JavaScript the implementation language of Node?

There are three main reasons for choosing JavaScript as the implementation language for Node:

  • A high performance
  • Event-driven compliance
  • No historical baggage

Ryan Dahl evaluated C, Lua, Haskell, And Ruby as alternative implementations, but C had a high threshold of development, Lua had a lot of historical baggage, Haskell felt that it could not play, and The performance of The Ruby virtual machine was not very good. Under synthesis, JavaScript is chosen as the implementation language of Node

You might be thinking, like me, doesn’t JavaScript have any historical baggage? Yes, JavaScript has never had a market on the back end, and the historical baggage amounts to zero

5. What are the main features of Node?

The main features are as follows:

  • Asynchronous I/O
  • Event and callback functions
  • Single thread

Node retains the familiar interfaces of JavaScript, the front-end browser, without rewriting any features of the language itself

6. What are the application scenarios of Node?

Node can be used in the following scenarios:

  • cpu-intensive
  • CPU intensive services
  • Distributed application

Node uses the processing power of event loops to organize more hardware resources more efficiently by eliminating the need to start a thread for each request. Node is also efficient enough for businesses that are heavy on CPU stacks, mainly due to V8’s deep performance optimizations

7. What challenges will CPU intensive applications bring to Node and how to solve them?

The main challenge that CPU-intensive applications present to Node is that because JavaScript is single threaded, long computations (such as large loops) will result in CPU time slices that cannot be released and subsequent I/ OS cannot be initiated

General scheme:

  • Adjust and decompose large computing tasks appropriately

If that doesn’t work, Node has two other ways to make the most of its CPU

  • Node can write C/C++ extensions
  • A portion of Node processes are used for computation as resident server processes by child processes, and the result is passed through inter-process messages, separating computation from I/O

reference

Node.js