Understanding the Node.js event loop can be very strenuous for beginners and even for experienced developers as well.

I will try to explain in a simpler way about the event loop in this article.

Why Do we need Event Loop?

For performing the asynchronous code in the applications.

The process involved in the event loop:

  1. Node looks at pendingTimers and sees if any functions(scheduled by setTimeOut & setInterval) are ready to be called.
  2. Node.js looks at pendingOS tasks and pending operations and call relevant callbacks.
  3. In this step, it pauses the execution and continues when timer or pending operation or pending OS tasks is done.
  4. Look at the pending timer- that is setImmediate
  5. Handles any close events

Understanding only these 5 points will give some basic idea about the event loops.