DEV Community

rukotanafreddy250
rukotanafreddy250

Posted on • Updated on

My understanding of an event loop in Nodejs

What is the Event Loop?

The event loop is what allows Nodejs to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.

Event loop explained

When Node.js starts, it initializes the event loop, processes the provided input script which may make async API calls, schedule timers, or call process.nextTick(), then begins processing the event loop.

Alt Text

this diagram shows how event loop order of operations

Each phase has a FIFO queue of callbacks to execute. When the queue has been exhausted or the callback limit is reached, the event loop will move to the next phase, and so on.

Top comments (0)