Node.js Interview Questions and Answers
Runtime internals, the event loop, streams, clustering and Express patterns.
Whether you are preparing for entry-level Node.js interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.
1 How does the Node.js event loop differ from the browser event loop? Medium
Node uses libuv and phases its loop: timers, pending callbacks, poll, check (setImmediate) and close callbacks, with process.nextTick and promise microtasks draining between phases.
Differences from the browser:
- Node has setImmediate (runs in the check phase) and process.nextTick (runs before promises).
- No DOM or rendering; instead there is filesystem, network, crypto and worker threads.
- Microtasks run after each phase callback, and nextTick has highest priority.
Ordering: nextTick > promise microtasks > setImmediate/timers (relative order of setImmediate and setTimeout(0) can vary).
2 What are streams and what are the four types? Medium
Streams process data in chunks instead of buffering everything, which keeps memory flat for large files and real-time traffic. Four types:
- Readable: source of data (fs.createReadStream, http request).
- Writable: destination (fs.createWriteStream, http response).
- Duplex: both, such as a TCP socket.
- Transform: duplex that modifies data as it passes (zlib.createGzip, a parser).
Pipelines propagate backpressure and errors:
const { pipeline } = require('node:stream/promises');
await pipeline(
fs.createReadStream('in.csv'),
new Transform({ transform(c, _e, cb) { cb(null, c.toString().toUpperCase()); } }),
fs.createWriteStream('out.csv'),
);
3 How do you handle errors in asynchronous Node.js code? Medium
For promises and async functions use try/catch and let errors propagate to a central handler:
app.get('/users/:id', asyncHandler(async (req, res) => {
const user = await repo.find(req.params.id);
if (!user) throw new NotFoundError();
res.json(user);
}));
Patterns:
- asyncHandler wraps async routes so rejected promises reach Express error middleware.
- Distinguish operational errors (bad input, network) from programmer errors; only operational errors should be retried/reported to users.
- Attach handlers to streams (.on('error')), EventEmitters and process level 'unhandledRejection'/'uncaughtException' as a last resort, then exit cleanly.
- Use a structured logger and never leak stack traces to clients.
Frequently Asked Questions About Node.js Interviews
What do hiring managers evaluate in Node.js technical rounds?
Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.
What are the best interview tips for practicing Node.js questions?
Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.