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.
- Event loop
- Streams
- Express
- Security
- Worker threads
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
Node.js · Junior
- 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.
- 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.
- 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.
- Which of these is NOT available in Node.js by default?
Correct answer:
documentand the DOMThere is no page in Node.js, so there is no
documentorwindow. Instead Node.js provides modules such asfs,httpandprocess. Timers andconsoleexist in both environments.
Node.js · Middle
- 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/setIntervalcallbacks, poll waits for and runs I/O callbacks, check runssetImmediate, close runscloseevents. There is no render step: that's a browser concept. - Why can recursive
process.nextTickcalls 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.
setImmediatelets the event loop process I/O between iterations. - What does the libuv thread pool handle by default?
Correct answer: File system operations,
dns.lookup, somecrypto(likepbkdf2,scrypt) andzlibworkNetwork 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. - 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 withsetImmediatebetween them.
Node.js · Senior
- 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.
- 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-sizeto fit the container, leaving room for Buffers and native memoryRecent 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.
- Which pattern is a classic cause of a memory leak in a Node.js server?
Correct answer: A module-level
Mapused as a cache that is filled on every request and never evictedAnything reachable from a module-level object lives forever. Use a bounded LRU cache with TTL, a
WeakMapkeyed by objects, or an external cache like Redis. - 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 growingThe comparison view shows objects allocated between snapshots, and retainer paths show what keeps them alive.
--heapsnapshot-near-heap-limitcan take a snapshot right before a crash.
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 →