A focused set of Node.js interview questions with concise, correct answers, covering the event loop, async patterns, modules, streams, and common gotchas. Useful whether you're preparing for an interview or screening candidates.
What is Node.js? A runtime that executes JavaScript outside the browser, built on Chrome's V8 engine. It uses a single-threaded, event-driven, non-blocking I/O model, ideal for I/O-heavy, concurrent workloads.
Is Node.js single-threaded?
JavaScript execution runs on a single thread (the event loop), but Node offloads I/O and CPU-heavy work to a background thread pool (libuv) and the OS. Since Node 12+, worker_threads allow true multi-threaded CPU work.
What is the event loop? The mechanism that lets Node perform non-blocking I/O despite being single-threaded. It continuously processes phases, timers, pending callbacks, poll, check, close, running queued callbacks when the call stack is empty.
Explain the event loop phases.
timers (setTimeout/setInterval) → pending callbacks → poll (I/O events) → check (setImmediate) → close callbacks. Microtasks (Promises, process.nextTick) run between each phase.
Callbacks vs Promises vs async/await?
Callbacks are functions passed to be invoked later (prone to "callback hell"). Promises represent a future value with .then()/.catch() chaining. async/await is syntactic sugar over Promises that reads like synchronous code.
process.nextTick() vs setImmediate()?
process.nextTick() callbacks run before the event loop continues (after the current operation). setImmediate() runs on the next check phase iteration. nextTick has higher priority, overusing it can starve the loop.
What is callback hell and how do you avoid it?
Deeply nested callbacks that become unreadable. Avoid with Promises, async/await, named functions, or modularization.
How do you handle errors in async/await?
Wrap in try/catch. For unhandled rejections, listen on process.on('unhandledRejection', ...).
async function load() {
try {
const data = await fetchData();
return data;
} catch (err) {
console.error("failed:", err);
}
}CommonJS vs ES Modules?
CommonJS uses require()/module.exports, loaded synchronously (default historically). ES Modules use import/export, are statically analyzable, and support top-level await. Use .mjs or "type": "module" in package.json for ESM.
What is module.exports vs exports?
exports is a reference to module.exports. Reassigning exports = ... breaks the link; always assign to module.exports when exporting a single value.
What are streams? Objects for reading/writing data piece by piece instead of all at once, efficient for large files or network data. Four types: Readable, Writable, Duplex, Transform.
const fs = require("fs");
fs.createReadStream("big.log")
.pipe(fs.createWriteStream("copy.log"));What is a Buffer? A fixed-length chunk of memory for handling raw binary data outside V8's heap, used for file/network I/O.
How does require() caching work?
Modules are cached after first load; subsequent require() calls return the cached export. Clear with delete require.cache[...] (rarely needed).
What is the difference between npm and npx?
npm installs/manages packages; npx executes a package binary without a global install.
How do you scale a Node.js app across CPU cores?
Use the cluster module or worker_threads, or run multiple instances behind a load balancer (PM2, Kubernetes). Node's single thread can't use multiple cores alone.
What is middleware (Express)?
Functions with signature (req, res, next) that run in order on each request, used for logging, auth, parsing, error handling. Call next() to pass control.
How do you prevent blocking the event loop?
Avoid synchronous APIs (fs.readFileSync), heavy CPU loops, and large JSON parsing on the main thread. Offload to worker_threads or break work into chunks.
| Topic | Can they explain… |
|---|---|
| Event loop | phases + microtask timing |
| Async | callbacks → Promises → async/await + error handling |
| Modules | CommonJS vs ESM |
| Streams | when and why to use them |
| Scaling | cluster / worker_threads |
| Express | middleware order and next() |
Maintained by the team at EchoGlobal. Hiring Node.js talent? See our curated lists of Top Node.js Experts, Top JavaScript Engineers, and Top Express.js Experts on GitHub, or hire pre-vetted developers in days.