What is the architecture and workflow of Node.js?

Overview

Node.js is a platform built on a JavaScript foundation. It operates on the JavaScript V8 engine present in Google Chrome. It helps us develop web and single-page applications. Node.js is used by both large organizations as well as upcoming start-up companies.

Node.js architecture

Node.js architecture uses the 'single-threaded event loop' architecture for handling multiple client requests.

Node.js architecture

Parts of the Node.js architecture

  1. Node.js server: The Node.js server receives user requests, processes them, and sends feedback to the users. It is the server-side of the platform.
  2. Event queue: The event queue helps in request handling. It arranges incoming requests and sends them for processing one after the other.
  3. Requests: These are the tasks users try to perform on web applications. They are sent to the web application's server.
  4. Thread pool: These are the number of available threads used to carry out every incoming request by the user.
  5. Event loop: The event loop receives requests from clients, processes them, and sends them back to the client.
  6. External resources: These are resources that help perform client requests. The request could be computational or requires data storage.

Workflow in Node.js

Workflow in Node.js
  1. A request is sent to the server by the client. The request could be to delete data, query data, update data, and so on.
  2. The request is received by the event queue and kept for processing.
  3. The events are sent in the order they were received through the event loop. A check is also performed to know if any event requires external resources.
  4. The event loop processes the request (input/output) output polling and sends the feedback to the client.

Advantages of using Node.js

  1. Fewer resources are required in the operations carried out in the Node.js server.
  2. Node.js can handle multiple concurrent requests with ease. This is made possible through the event queue and the thread pool.
  3. Node.js does not need multiple threads because the event loop helps handle the events one after the other.

Free Resources