Node Js
What is Node.js?
Node.js can be used to create scalable, server-side applications using JavaScript, including command-line applications, web applications, real-time chat applications, REST API servers, as well as network programs like web servers.
Advantages of Node.js
- Node.js is open-source meaning it has been made freely available to developers all over the world. Anyone is able to proposed modifications or improvements.
- Using Node.js we are able to build entire server-side applications using only JavaScript.
- The runtime environment itself is very lightweight. It includes only the core modules needed to function. Any other modules required by the application may be easily installed.
- The asynchronous nature of Node.js leads to increased performance over other frameworks.
- Node.js may be run on Windows, MAC, or Linux systems.
The Web Server Model
The Node.js Process Model
There are two scenarios that will occur depending on the nature of the request. If the request is non-blocking, it does not involve any long-running processes or data requests, the response will be immediately prepared and then sent back to the client. In the event the request is blocking, requiring I/O operations, the request will be sent to a worker thread pool. The request will have an associated call-back function that will fire when the request is finished and the worker thread can send the request to the event loop to be sent back to the client. In this way, when the single thread receives a blocking request, it hands it off so that the thread can process other requests in the meantime. In this way Node.js is inherently asynchronous.
The combination of the asynchronous nature of Node.js plus the reduced resource consumption of the single-threaded process leads to a significant increase in performance. It should be noted, however, that Node.js does not excel with CPU-intensive operations such as image processing and computationally-expensive work.