100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Node.js

Common Node.js Interview Questions

A curated set of frequently asked Node.js interview questions with clear, technically accurate answers.

Interview PrepIntermediate14 min readJul 8, 2026
Analogies

Overview

Node.js interviews typically probe your understanding of the event loop, asynchronous programming, the module system, and how Node handles I/O and concurrency without traditional multithreading. This guide walks through the questions that come up most often, with concise, accurate answers you can use to prepare or to sanity-check your own understanding before an interview.

🏏

Cricket analogy: A batting coach quizzes a young player not just on technique but on match awareness — reading the field, judging a run, playing to conditions — much like Node interviews probe the event loop and async concurrency beyond syntax.

Frequently Asked Questions

Q: What is the event loop and what phases does it have?

The event loop is the mechanism that lets single-threaded Node.js perform non-blocking I/O by offloading operations to the system kernel or a thread pool and processing their callbacks later. Its main phases, in order, are: timers (setTimeout/setInterval callbacks), pending callbacks (deferred I/O callbacks), poll (retrieving new I/O events and executing their callbacks), check (setImmediate callbacks), and close callbacks (e.g., socket.on('close')). Between phases, Node drains the microtask queue (process.nextTick, then Promise callbacks).

🏏

Cricket analogy: The event loop is like an umpire cycling through fixed duties each over: checking the clock for the drinks break (timers), reviewing deferred no-ball calls (pending callbacks), watching live play (poll), signaling boundaries (check), and closing the innings (close), pausing for urgent DRS reviews (microtasks) between each.

Q: What is the difference between blocking and non-blocking code?

Blocking code executes synchronously and halts the entire event loop until it finishes, such as fs.readFileSync. Non-blocking code, like fs.readFile, starts an operation and immediately returns control to the event loop, with a callback (or promise) invoked once the operation completes. Because Node is single-threaded for JavaScript execution, blocking calls in hot paths can freeze the whole application for all concurrent requests.

🏏

Cricket analogy: A blocking call is like a rain delay where the entire match halts and nothing else happens until it clears (fs.readFileSync), while a non-blocking call is like play continuing on another ground while groundstaff handle the covers (fs.readFile).

Q: How does Node.js achieve concurrency if it's single-threaded?

Node's JavaScript execution runs on a single thread, but I/O operations (file system, network, DNS) are delegated to the operating system's asynchronous APIs or to libuv's thread pool (default size 4). The event loop polls for completed operations and dispatches their callbacks back onto the single JS thread, giving the appearance of concurrency for I/O-bound workloads while CPU-bound work still runs sequentially on that one thread.

🏏

Cricket analogy: The captain (single JS thread) makes all tactical calls personally, but delegates ball retrieval and pitch checks to four designated fielders (libuv's thread pool of 4), giving the illusion of the whole team acting at once.

Q: What's the difference between CommonJS and ES modules in Node.js?

CommonJS (require/module.exports) loads modules synchronously and resolves them at runtime, allowing conditional and dynamic requires. ES modules (import/export) are statically analyzed, loaded asynchronously, support top-level await, and are enabled via the .mjs extension or "type": "module" in package.json. ESM imports are live bindings to the exported values, whereas CommonJS exports are copies of the values at the time of require, unless you export an object and mutate its properties.

🏏

Cricket analogy: CommonJS is like picking players from the squad list on match day, resolved right there (require), while ES modules are like the pre-announced official team sheet locked in before the toss, statically known and unchangeable mid-innings.

Q: What is the difference between a process and a thread, and how does Node use them?

A process is an independent instance of a running program with its own memory space; a thread is a unit of execution within a process that shares that process's memory. Node.js runs your JavaScript on a single main thread within one process, but internally uses libuv's thread pool for certain blocking operations (like some fs, crypto, and DNS calls) and can spawn additional OS processes via child_process or additional threads via worker_threads for CPU-intensive work.

🏏

Cricket analogy: A cricket board (process) runs its own tournament with its own budget and rules, while individual players (threads) on a team share the same dressing room and resources within that board's structure.

Q: What is the cluster module and when would you use it?

The cluster module lets a Node.js application spawn multiple worker processes that share the same server port, each running its own event loop and V8 instance, effectively utilizing multiple CPU cores. It's used to scale a single-threaded Node app horizontally on a multi-core machine; the master process forks workers and load-balances incoming connections across them, and if a worker crashes it can be respawned without taking down the whole app.

🏏

Cricket analogy: The cluster module is like a franchise running four identical net sessions on four pitches simultaneously, with a head coach (master process) assigning new batters to whichever pitch is free and replacing an injured coach without stopping the others.

Q: What are Streams in Node.js and why are they useful?

Streams are objects that let you read or write data piece by piece (in chunks) instead of loading it all into memory at once. Node has four types: Readable, Writable, Duplex, and Transform. They're useful for processing large files, proxying HTTP responses, or piping data between sources and destinations efficiently, since data flows and is processed incrementally, keeping memory usage low and improving time-to-first-byte.

🏏

Cricket analogy: Streams are like watching a match ball-by-ball on TV instead of waiting for the full scorecard after the game — you process each delivery (chunk) as it happens rather than loading the entire five-day Test into memory at once.

Q: What is a Buffer in Node.js?

A Buffer is a fixed-size chunk of raw binary data allocated outside the V8 JavaScript heap, used to handle binary data such as file contents, TCP streams, or images. Because JavaScript strings weren't originally designed for binary data, Node introduced the Buffer class to work directly with octets efficiently, and it's the underlying data type used by Streams when working with binary content.

🏏

Cricket analogy: A Buffer is like the raw stump-cam footage stored on a dedicated recorder outside the broadcast truck's main editing suite — it holds binary video data efficiently, separate from the readable scorecard text.

Q: What is child_process and what methods does it provide?

The child_process module lets Node.js spawn and interact with OS-level subprocesses, useful for running shell commands or CPU-heavy tasks outside the main event loop. Key methods are exec (buffers output, runs via a shell, good for short commands), execFile (runs a file directly without a shell), spawn (streams output, ideal for long-running or large-output processes), and fork (spawns a new Node.js process with an IPC channel for message passing, commonly used with the cluster module).

🏏

Cricket analogy: child_process is like a captain delegating tasks off the field: exec is shouting a quick instruction to a nearby steward (buffered, via shell), spawn is assigning a scout to continuously radio updates (streamed), and fork is deploying an assistant coach with a dedicated walkie-talkie channel (IPC).

Q: What is the difference between process.nextTick() and setImmediate()?

process.nextTick() queues a callback to run immediately after the current operation completes, before the event loop continues to the next phase — it has higher priority than Promises and all event loop phases. setImmediate() queues a callback to run in the check phase of the event loop, after I/O callbacks in the current iteration. In practice, nextTick callbacks always run before setImmediate callbacks when both are scheduled from the main module.

🏏

Cricket analogy: process.nextTick() is like an urgent DRS review that gets resolved before the umpire even signals the next delivery, while setImmediate() is like a routine boundary-rope check done during the scheduled drinks break — nextTick always jumps the queue first.

Quick Reference

  • Event loop phases run in order: timers, pending callbacks, poll, check, close callbacks.
  • process.nextTick and Promise microtasks run between every phase, before the loop continues.
  • Blocking (sync) calls freeze the entire event loop for all clients; prefer async APIs.
  • libuv's default thread pool size is 4, used for fs, crypto, and DNS lookups.
  • CommonJS is synchronous and dynamic; ES modules are static and support top-level await.
  • The cluster module forks one process per CPU core to share a listening port.
  • worker_threads share memory via SharedArrayBuffer; child_process does not share memory.
  • Streams process data in chunks, keeping memory usage bounded for large payloads.
  • Buffers hold raw binary data outside the V8 heap.
  • spawn/fork stream output; exec/execFile buffer output and are shell/file based respectively.

Key Takeaways

  • Node.js is single-threaded for JS execution but achieves concurrency via the event loop and libuv's async I/O and thread pool.
  • Understanding the event loop's phases and microtask timing is the single most tested Node.js interview topic.
  • CommonJS and ES modules differ in loading strategy (sync vs static/async) and binding semantics (copy vs live reference).
  • Use cluster or worker_threads to scale CPU-bound or multi-core workloads; child_process for isolated external tasks.
  • Streams and Buffers exist to handle data efficiently without loading everything into memory at once.

Practice what you learned

Was this page helpful?

Topics covered

#NodeJs#NodeJsExpressStudyNotes#WebDevelopment#CommonNodeJsInterviewQuestions#Common#Node#Interview#Questions#StudyNotes#SkillVeris