← All topics

Node.js Interview Questions and Answers

The event loop and asynchrony, modules, streams and Buffer, the file system and HTTP, Express and Fastify, security, worker threads and scaling Node.js services.

225 questions for Node.js interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.

Questions by level

Sample questions

A few questions from each level with the correct answer and an explanation.

Node.js · Junior

  1. What is Node.js?

    Correct answer: A JavaScript runtime built on the V8 engine that runs JavaScript outside the browser

    Node.js takes the V8 engine from Chrome and adds APIs for the file system, network, processes and more. It is used for servers, CLIs, build tools and scripts.

  2. Which JavaScript engine does Node.js use?

    Correct answer: V8

    V8 is Google's engine, also used in Chrome. SpiderMonkey powers Firefox and JavaScriptCore powers Safari. Other runtimes such as Bun use JavaScriptCore.

  3. What model does Node.js use to handle many connections at once?

    Correct answer: A single-threaded event loop with non-blocking I/O

    JavaScript runs on one main thread. I/O such as reading files or network calls is handed off to the system and libuv, and the callback runs later, so one process can serve thousands of connections.

  4. Which of these is NOT available in Node.js by default?

    Correct answer: document and the DOM

    There is no page in Node.js, so there is no document or window. Instead Node.js provides modules such as fs, http and process. Timers and console exist in both environments.

All 75 questions with answers →

Node.js · Middle

  1. Which list shows the main phases of the Node.js event loop in order?

    Correct answer: timers → pending callbacks → poll → check → close callbacks

    Timers run setTimeout/setInterval callbacks, poll waits for and runs I/O callbacks, check runs setImmediate, close runs close events. There is no render step: that's a browser concept.

  2. Why can recursive process.nextTick calls be dangerous?

    Correct answer: The nextTick queue is drained completely before the loop continues, so endless nextTicks starve I/O

    The same applies to an endless chain of microtasks. setImmediate lets the event loop process I/O between iterations.

  3. What does the libuv thread pool handle by default?

    Correct answer: File system operations, dns.lookup, some crypto (like pbkdf2, scrypt) and zlib work

    Network sockets use the OS's async mechanisms (epoll, kqueue, IOCP) and don't need the pool. The pool has 4 threads by default, configurable with UV_THREADPOOL_SIZE.

  4. A request handler runs a CPU-heavy loop for 2 seconds. What happens to other requests?

    Correct answer: They wait: while JavaScript runs on the main thread, the event loop can't handle anything else

    Move heavy CPU work to worker_threads, a separate service or a job queue, or split it into small chunks with setImmediate between them.

All 75 questions with answers →

Node.js · Senior

  1. How is the V8 heap organized for garbage collection?

    Correct answer: Into a young generation (new objects, collected often by a fast scavenger) and an old generation (long-lived objects, collected by mark-sweep-compact)

    Most objects die young, so frequent cheap scavenges reclaim them. Objects that survive are promoted to the old generation, whose collections are rarer and more expensive, though mostly concurrent and incremental.

  2. A container has 2 GB of memory, but the Node.js process crashes with 'JavaScript heap out of memory' at about 1.4 GB. What should you check?

    Correct answer: The V8 old-space limit: set --max-old-space-size to fit the container, leaving room for Buffers and native memory

    Recent Node.js versions size the heap from the container's memory limit, but the heap is not all memory: Buffers, native code and thread stacks live outside it. Leave a margin.

  3. Which pattern is a classic cause of a memory leak in a Node.js server?

    Correct answer: A module-level Map used as a cache that is filled on every request and never evicted

    Anything reachable from a module-level object lives forever. Use a bounded LRU cache with TTL, a WeakMap keyed by objects, or an external cache like Redis.

  4. How do you find what is leaking in a Node.js process?

    Correct answer: Take several heap snapshots over time (v8.writeHeapSnapshot() or DevTools) and compare which object counts keep growing

    The comparison view shows objects allocated between snapshots, and retainer paths show what keeps them alive. --heapsnapshot-near-heap-limit can take a snapshot right before a crash.

All 75 questions with answers →

Coding tasks

Write your solution right in the browser, and tests check it instantly. JavaScript interview classics (debounce, deepClone, Promise.all, an LRU cache) and React components and hooks like a todo list, tabs, useDebounce and useInterval.

Open tasks →