πŸ“š Learning Hub
Β· 3 min read
Last updated on

10 Node.js Interview Questions Senior Developers Get Wrong


Node.js interviews test whether you understand the runtime, not just JavaScript. If you need to brush up on the language fundamentals first, see our JavaScript interview questions. These questions trip up even experienced developers.

1. Explain the event loop

Node.js is single-threaded but non-blocking. The event loop processes callbacks in phases:

  1. Timers β€” setTimeout, setInterval callbacks
  2. I/O callbacks β€” file system, network callbacks
  3. Poll β€” retrieve new I/O events
  4. Check β€” setImmediate callbacks
  5. Close β€” socket.on('close') callbacks

process.nextTick() runs between every phase (before any other callbacks). Promise.then() runs in the microtask queue (after nextTick, before the next phase).

2. What’s the difference between process.nextTick() and setImmediate()?

process.nextTick() fires before the event loop continues. setImmediate() fires on the next iteration of the event loop.

setImmediate(() => console.log('immediate'));
process.nextTick(() => console.log('nextTick'));
// Output: nextTick, immediate

Danger: Recursive process.nextTick() starves the event loop. Prefer setImmediate() for recursive operations.

3. How do you handle uncaught exceptions?

// Catch unhandled promise rejections
process.on('unhandledRejection', (reason, promise) => {
  console.error('Unhandled rejection:', reason);
  // Log, alert, then gracefully shutdown
});

// Catch uncaught exceptions (last resort)
process.on('uncaughtException', (err) => {
  console.error('Uncaught exception:', err);
  process.exit(1); // Must exit β€” state is unreliable
});

Senior answer: β€œuncaughtException should trigger a graceful shutdown, not recovery. The process state is unknown after an uncaught exception.”

4. Explain streams and when to use them

Streams process data in chunks instead of loading everything into memory:

// ❌ Loads entire 2GB file into memory
const data = fs.readFileSync('huge.csv');

// βœ… Processes chunk by chunk
const stream = fs.createReadStream('huge.csv');
stream.on('data', chunk => process(chunk));

Four types: Readable, Writable, Duplex (both), Transform (modify data as it passes through).

5. How do you scale Node.js beyond one CPU core?

Cluster module β€” fork multiple worker processes:

const cluster = require('cluster');
const os = require('os');

if (cluster.isPrimary) {
  for (let i = 0; i < os.cpus().length; i++) {
    cluster.fork();
  }
} else {
  app.listen(3000);
}

Alternatives: PM2 (manages clustering for you), Docker containers (one process per container, scale horizontally), worker threads (for CPU-intensive tasks within a process). If you’re choosing a framework for your clustered app, see our Express vs Fastify vs Hono comparison.

6. What causes memory leaks in Node.js?

  1. Global variables that accumulate data
  2. Event listeners not removed (especially in long-running servers)
  3. Closures holding references to large objects
  4. Caching without eviction β€” unbounded Maps/Objects

Debug: --inspect flag + Chrome DevTools β†’ Memory tab β†’ Heap snapshots.

7. CommonJS vs ES Modules

// CommonJS (require) β€” synchronous, dynamic
const fs = require('fs');
if (condition) { const lib = require('./lib'); }

// ES Modules (import) β€” async, static, tree-shakeable
import fs from 'fs';
// import is hoisted, can't be conditional

Node.js supports both. Use ES Modules for new projects ("type": "module" in package.json). You might also be asked about alternative runtimes β€” see Bun vs Node for how they compare.

8-10: Quick answers

8. What’s libuv? The C library that provides Node’s event loop, async I/O, thread pool, and cross-platform abstractions. The thread pool (default 4 threads) handles file system operations and DNS lookups.

9. How does require() caching work? Modules are cached after first load. require('./module') returns the same object every time. This is why module-level variables act like singletons.

10. What’s backpressure in streams? When a writable stream can’t keep up with a readable stream. The readable pauses until the writable catches up. Handle with .pipe() (automatic) or check writable.write() return value (manual).

FAQ

What Node.js questions are asked in interviews?

The most common Node.js interview questions cover the event loop, streams, clustering, memory leaks, error handling, CommonJS vs ES Modules, and the difference between process.nextTick() and setImmediate(). Senior-level interviews also ask about backpressure, libuv, and scaling strategies.

Should I know Express for Node interviews?

Yes, Express is still the most widely used Node.js framework and interviewers often expect familiarity with middleware patterns, routing, and error handling. However, you should also be aware of alternatives like Fastify and Hono, as some companies have moved to faster frameworks.

Do I need to know TypeScript?

Increasingly, yes. Most production Node.js codebases in 2026 use TypeScript. Interviewers may ask you to write TypeScript during coding exercises or ask about type safety in API design. At minimum, you should be comfortable reading and writing basic TypeScript.

How do I prepare for Node.js interviews?

Focus on understanding the runtime, not just the API surface. Study the event loop phases, practice explaining streams and backpressure, and be ready to discuss how you’d debug memory leaks and scale beyond a single process. Build a small project that uses clustering and streams to solidify your understanding.


Related: npm Cheat Sheet Β· Node.js Complete Guide

πŸ“˜