What is Node.JS & why it is popular?
A lot of the confusion for beginners to Node is misunderstanding exactly what it is.
- An important thing to realize is that Node is not a web server. By itself it doesn’t do anything.It doesn’t work like Apache.There is no config file where you point it to your HTML files.
To start using Node.JS, you must first understand the difference between Node.JS and traditional server-side scripting environment.
-Other scripting languages uses separate server like Apache or nginx to run the application,which is the thread and process based, which means if the process is waiting for the I/O, whole thread is blocked.
-Whereas Node.JS using the ‘HTTP’ module can run on a stand-alone web server. It is asynchronous, event driven I/O. Every nodes instance runs in a single thread, so it can handle more number of concurrent requests as compared to Apache.
What makes Node.JS fast?
Second, How fastly Node handles connections.
When 100 people connect at once, rather than having different threads, Node will loop over those connections and fire off any events your code should know about. If a connection is new it will tell you .If a connection has sent you data, it will tell you .If the connection isn’t doing anything ,it will skip over it rather than taking up precision CPU time on it. Everything in Node is based on responding to these events. So we can see the result, the CPU stay focused on that one process and doesn’t have a bunch of threads for attention.There is no buffering in Node.JS application it simply output the data in chunks.
Examples where Node.JS can be use
-Server side web application
One can exploits the benefits of the Node.JS, when the use-case does not contain any CPU intensive operation or not having blocking resources,so can enjoy fast scalable network application.