Before, many things were achieved by encapsulation within some environments like Adobe Flash and Java Applets. But, by now, you’ll have to know that by incorporating NodeJS in the stack, one of the most significant benefits you’ll get is to reuse the dev resources optimally.
Why Is NodeJS Any Different From Those Technologies Before?
NodeJS is so revolutionary because, after more than two decades, we finally got a two-way connection web app where data exchange runs freely, allowing both the client and the server to start the communication. After so much time with those stateless request-response model-based web apps, NodeJS was quite refreshing for web developers.
This is a considerable contradiction when we consider the usual web response model, in which the client is the one to start the client-server communication, and no exceptions are made.
It may be arguable that all this was possible years before NodeJS thanks to Adobe Flash and the Java Applets, while that technology was only using the web as nothing more than a medium to get delivered to the client. Specifically, those sandboxed environments used the web only as a transport protocol.
Also, we should consider that with the standard web response model, all the communication went over the standard port. At the same time, the sandboxed environments were often run over non-standard ports. So again, these environments often require special permissions to operate. As a result of everything NodeJS offers, the technology now plays a critical role in some of the biggest and most high-profile companies worldwide.
How Node JS Handles Multiple Requests and How Fewer Threads Are Helping Here?
Although NodeJS is pretty sophisticated, we could use this analogy on how Node JS handles multiple requests – so there is the main “event loop,” which would constantly be asleep until work is done. Then, when there is work on sight, the main “event loop” would be waking and doing the work.
The EventLoop is the listener for the EventQueue, or how else the EventLoop would know that a client request has to be processed. Now, when NodeJS gets more than one request, they are placed in this EventQueue where they wait until the EventLoop is free again.
If Node can process this client request without blocking the Input/Output, then the EventLoop would process the information and send the request response back to the client. It’s important to state that there is a way for multiple requests to be processed simultaneously with no queue time with the help of NodeJS’s worker_threads cluster module.