Introduction to How Node. JS works

In this post, I will try to give an easy way to understand overview of what makes Node.JS different and make it clear that it’s more than just server-side JavaScript.


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.
  • If you want it to be a HTTP server,you have to write an HTTP server by using its built in libraries.Node.JS is just another way to execute code in your computer. It is simply a JavaScript run-time.

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.


Apache_scripting


-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.


Untitled

 

 

What makes Node.JS fast?

First, Node is powered by Google’s V8 JavaScript Engine. The thing running you JavaScript code is the exact same thing the Chrome browser uses to run JavaScript code.


Now Question is why V8 JavaScript Engine?


-It has unique speed compare to other JavaScript engines, it compiles JavaScript directly into native machine code, while other languages PHP & Ruby, Java all have to run through an interpreter every time when they are accessed. Node will run your code as though it’s native application. So it screams with speed.


Second, How fastly Node handles connections.


Untitled1

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

-Chat application

-Data Streaming,etc.

 

Conclusion:

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.

Write a comment
Cancel Reply
  • Mak June 11, 2018, 1:41 am
    Understanding node is quite tricky.
    reply