Skip to content
UniCircle
GuideEngineeringB.Tech / B.E., BCA, MCA

The Node.js event loop, explained for placement interviews

Why Node can serve many users on one thread, the order in which synchronous code, process.nextTick, promises and timers run, and how to answer 'what does this print?' questions.

By UniCircle team1 min readPublished 22 Oct 2026Undergraduate

Node.js runs your JavaScript on a single main thread. Slow work such as reading files or waiting for the network is handed to the system, and when it finishes, a callback is queued. The event loop takes queued callbacks one at a time and runs them.

The order that matters

  1. All synchronous code in the current script or callback runs to the end.
  2. Then the process.nextTick queue empties.
  3. Then the promise (microtask) queue empties: .then callbacks and code after await.
  4. Then the loop moves through its phases: timers (setTimeout, setInterval), I/O callbacks, setImmediate, close callbacks, and empties the two queues again between each callback.
JavaScript
console.log('1 sync start');
setTimeout(() => console.log('5 timeout'), 0);
Promise.resolve().then(() => console.log('4 promise'));
process.nextTick(() => console.log('3 nextTick'));
console.log('2 sync end');
text
1 sync start
2 sync end
3 nextTick
4 promise
5 timeout

A detail interviewers like

In the main script, setTimeout(fn, 0) and setImmediate(fn) can run in either order, because it depends on how quickly the loop starts. Inside an I/O callback, setImmediate always runs first:

JavaScript
const fs = require('fs');
fs.readFile(__filename, () => {
  setTimeout(() => console.log('timeout'), 0);
  setImmediate(() => console.log('immediate'));
});
text
immediate
timeout

Do not block the loop

While a callback runs, nothing else can. A long loop or a synchronous call such as fs.readFileSync on a big file in a request handler makes every other user wait. Use the asynchronous APIs, split heavy work, or move CPU-heavy work to worker threads. Practise more in UniCircle interview prep: web development.

#nodejs#event loop#microtasks#interview

Sources and further reading

Practise this as an interview question

Written by the UniCircle team, checked by an editor on 22 Oct 2026. It is not official policy of any university. Exam patterns and rules change; confirm dates and rules on the official website.

Keep reading