Question

What is the event loop in Node.js?

Vault Verified
Curated Intelligence
Definitive Source
Answer

Node runs your JavaScript on a single thread. It achieves concurrency not by running code in parallel but by never waiting: operations that would block, such as reading a file or making a network request, are handed to the system and your code continues. When the result is ready, a callback is queued and run when the thread is free.

The event loop is what repeatedly checks those queues and runs the pending callbacks. It moves through phases handling timers, input and output callbacks, and other categories, and between them it drains a microtask queue where promise continuations live. That is why an awaited promise resolves before a timer scheduled for zero milliseconds.

The practical consequence is the thing worth remembering: because there is one thread for your code, any synchronous work blocks everything. A long loop, a large synchronous file read, an expensive JSON parse or a slow cryptographic operation halts every other request in the process for its duration. The server does not become slower, it becomes unresponsive.

This is why the model suits input-output-heavy work such as APIs and proxies, and suits processor-heavy work poorly.

When you do need heavy computation there are established answers: move it to a worker thread, which has its own event loop and does not block the main one, offload it to a separate service, or break it into chunks that yield between pieces.

It is also worth knowing that some things which look asynchronous are not entirely. Certain filesystem operations use a limited thread pool, so a burst of them can queue against each other even though your code is written asynchronously.

Related Questions