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:
- Node looks at pendingTimers and sees if any functions(scheduled by setTimeOut & setInterval) are ready to be called.
- Node.js looks at pendingOS tasks and pending operations and call relevant callbacks.
- In this step, it pauses the execution and continues when timer or pending operation or pending OS tasks is done.
- Look at the pending timer- that is setImmediate
- Handles any close events
Understanding only these 5 points will give some basic idea about the event loops.