Node.js Event loop:

  1. V8 engine parses JavaScript scripts;
  2. The Node API might be called in the code, and the Node would be handed over to the LIBUV library
  3. The LIBUV library is responsible for executing the Node API. It assigns different tasks to different threads to form an Event Loop, which asynchronously returns the execution results of tasks to V8 engine.
  4. In an event-driven way, the results are put into an event queue and eventually delivered to our application.

Node.js initializes the event loop when it starts, processes the input script to call the asynchronous API, timer, or process.nexttick (), and then starts processing the event loop.

  1. Timers stage: This stage performs setTimeout() and setInterval() callbacks;
  2. The I/O callbacks stage performs callbacks except for close events and timers;
  3. Idle and prepare, used only for internal Node.
  4. The poll phase, which gets new I/O events, is where node blocks under appropriate conditions;
  5. The Check phase executes the setImmediate() callback;
  6. Callbacks in the close callbacks phase, such as socket.on(), are executed in this phase.

PS: To be continued, the above is just some of my superficial understanding, if you have any questions, please correct. ^ _ ^