Interview Q&A / Node.js

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What happens when you run a heavy CPU loop inside a Node.js request handler?

SHORT ANSWER

The single JavaScript thread is busy, so the event loop cannot serve any other request until the loop ends. Every user sees delays. Move heavy work to worker threads, a queue, or break it into chunks.

Explain it simply

A single cashier at a canteen can serve thousands of students quickly because each order takes seconds. Now suppose one student asks the cashier to count a huge bag of coins. Everybody else waits, even though their orders are tiny. Node's JavaScript thread is that cashier.

Example

js
const express = require("express");
const app = express();

app.get("/fast", (req, res) => res.send("hello"));

app.get("/slow", (req, res) => {
  let total = 0;
  for (let i = 0; i < 5e9; i++) total += i;   // blocks for several seconds
  res.send(String(total));
});

app.listen(3000);

While one browser waits on /slow, a request to /fast from another browser also hangs. Waiting on the database or network does not cause this, because those operations are handed to the operating system and the thread stays free. Only your own JavaScript computation, large JSON.parse, sync fs calls, or heavy regex block it.

Fixes:

  • Run the work in a worker_thread.
  • Push it into a job queue handled by another process.
  • Split it into small chunks and yield with setImmediate.

What to say in the interview

"Node runs JavaScript on one thread, so a long synchronous task blocks all requests. I keep handlers non-blocking and offload CPU-bound work to worker threads or a background queue."

Common mistakes

  • Assuming async/await makes CPU work non-blocking; it only helps with waiting.
  • Using synchronous file methods in request handlers.

#nodejs#event-loop#performance

Related questions

Practise more Node.js questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Node.js quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.