Node.js is designed to build scalable network applications as an asynchronous JavaScript event-driven runtime. The callback is executed on each connection, but Node.js will sleep if there is no work to be done. Node.js is similar in design to systems like Ruby’s EventMachine and Python’s Twisted and is influenced by them. The event model is taken a bit further by Node.js. Instead of a library, it presents an event loop as a runtime construct. There is always a blocking call to start the event-loop in other systems. Typically, the behavior is defined at the beginning of a script by callbacks, and a server is created at the end by a blocking call such as EventMachine:: run( ).
There is no such begin-the-event-loop call in Node.js. After executing the input script, Node.js enters the event loop. When there are no more callbacks to perform, Node.js exits the event loop. This behavior is like the JavaScript browser, which hides the event loop from the user.
HTTP, with streaming and low latency in mind, is a first-class citizen in Node.js. This makes Node.js suitable for a web library or framework foundation.
Designing Node.js without threads does not mean that multiple cores in your environment can not be taken advantage of. By using our child process .fork) (API, child processes can be spawned and are designed to be easy to communicate with. The cluster module, which allows you to share sockets between processes to enable load balancing over your cores, is built on that same interface.