Sunday 29 December 2019

What is Node JS and how it works

What is Node JS? 

Node is a open source and cross platform run time environment for executing JavaScript code outside of a browser, so basically node server executes the JavaScript code, not the browser. 

Node run time uses V8 engine and C++ program to execute JavaScript. 

How Node Works? 

  • Node applications are asynchronous by default. 
  • Node uses a single thread to handle all the requests. When the requests arrives, that single thread is used to handle all those. 
  • Node JS platform uses Single Threaded Event Loop model.

Example: 

“If we send a request to database, the thread doesn’t have to wait for the database to return the data. While database is executing query same thread will be used to serve another request. When the database returns the result it puts a message in the Event Queue. Node continuously monitors this event queue in background and when it finds an event in the queue it takes it and process it”.

No comments:

Post a Comment