Node.js Developer interview question

How does the Node.js event loop work?

Node.js executes JavaScript on an event-loop thread and delegates many I/O operations to the OS or libuv pool. Completed callbacks enter event-loop phases; long CPU work blocks all requests despite asynchronous APIs.

Direct answer

What a strong answer covers

How it works

Node runs JavaScript on one thread and hands file, DNS, compression, and some crypto work to a libuv thread pool, while network sockets are multiplexed by the OS. The loop cycles through phases: timers, pending callbacks, poll for I/O, check for setImmediate, close callbacks; process.nextTick and promise microtasks drain between each callback. Every callback runs to completion, so a synchronous 200 ms computation delays every other request by 200 ms regardless of how asynchronous the surrounding code looks. Throughput comes from keeping callbacks short and moving CPU work elsewhere.

Example

An API that hashes passwords with a synchronous bcrypt call handled 30 requests per second and froze all other endpoints during each hash; switching to the async variant, which runs in the thread pool, restored thousands of requests per second. A JSON.parse of a 100 MB body still blocks the loop because parsing is pure JavaScript, so large payloads are streamed or rejected.

Common mistakes

  • Believing that async syntax makes CPU-bound code non-blocking.
  • Recursing with process.nextTick and starving I/O callbacks.
  • Running one process on a 16-core machine and wondering why CPU is at 6 percent.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Node.js Developer interview questions