Home>America>tools

Node.js

About Node.js ® As an asynchronous event driven JavaScript runtime, Node.js is designed to build scalable web applications. In the "Hello World" example below, many connections can be processed concurrently, with each connection triggering a callback, and when there is nothing else to do, Node.js enters sleep mode. This is in stark contrast to the common concurrency model that uses operating system threads today. Thread based networks have relatively lower efficiency and are more difficult to use. In addition, due to the absence of locks, users of Node.js do not have to worry about process deadlocks. There are almost no functions in Node.js that directly perform I/O operations (unless you use the synchronized function version in the Node.js standard library), and its processes are never blocked, so it is very reasonable to use Node.js to develop scalable systems. If you have some confusion with the above description, here is an article specifically on blocking compared to non blocking for your reference. Node.js is designed similar to systems like Ruby's Event Machine or Python's Twisted. But Node.js delves deeper into the event model, presenting event loops as a runtime structure rather than a library. In other systems, there is always a blocking call used to initiate an event loop. Normally, the behavior to be executed is defined through a callback at the beginning of the script, and then a blocking call such as EventMachine:: run() is used to start the server. In Node.js, there is no such call for a startup event loop. Node.js enters the event loop directly after executing the input script, and exits the event loop when there are no more callbacks to execute. This behavior is like JavaScript in a browser - the event loop is hidden from the user. HTTP is a first-class citizen in Node.js, designed with streaming and low latency in mind, making Node.js ideal as the foundation for network libraries or frameworks. Node.js is designed to run on a single thread, but that doesn't mean you can't utilize multiple cores of the CPU. You can generate child processes through the child_ process. work() API, and it is designed to be very easy to communicate. The cluster module built on the same interface allows you to share sockets between processes to achieve core load balancing.

Tag: NODEJS

Reading: 30 2024-11-12

Recommend