Top 8 Nodejs Interview Questions
Browse 8 real-world technical and behavioral interview questions about Nodejs. Review scenarios, edge cases, and architectural best practices.
A promise rejects and nothing is awaiting it. What does Node do?
An unhandled promise rejection in Node.js means a promise failed before any code observed the error. Treat it as a bug, await or return the promise chain, and make the process-level handler a last-resort alarm.
Your Node service has low CPU but latency spikes for every request at the same moment. What is happening?
Node.js event loop blocking happens when synchronous JavaScript, JSON work, crypto, regex or CPU-heavy code occupies the shared thread. The signal is every endpoint slowing together while event loop delay rises.
Your logs are full of Cannot set headers after they are sent. Walk me through how a request gets into that state.
ERR_HTTP_HEADERS_SENT means an Express route tried to set status or headers after the response had already been sent. The usual cause is two response paths: missing return after res.send, async callbacks racing, or an error handler trying to respond after headers are committed.
A request fails but your Express error-handling middleware never runs. How do you work out why?
An Express error handler is skipped when it is not registered after routes, lacks the four-argument signature, or an async error never reaches next(). Express 4 needs explicit next(err) for rejected promises; Express 5 forwards them automatically.
How do you test a service that calls a third-party API, without calling it?
Substitute at the network layer or behind your own client interface, not at the HTTP library's function. Stubbing the library couples the test to how you make the call rather than to what you send, so the test keeps passing through refactors that change the request and breaks on refactors that change nothing.
A test passes on its own and fails when the whole suite runs. How do you track that down?
The failing test is a victim, not the cause: something earlier mutated state it shares, usually a module evaluated once, a global that was patched and not restored, or rows left in a database. Bisect the ordering to find the pair, then remove the sharing.
Why would you stream a large file rather than read it into memory, and what is backpressure?
Node.js stream backpressure prevents a fast producer from filling memory while a slow consumer catches up. The core signal is write() returning false and the producer waiting for drain before sending more.
You add one small npm package to a service. What have you just taken on?
Not one package but its whole transitive closure, install-time scripts from every node in it, a build that now depends on the registry being reachable, and the possibility of two resolved copies of the same library whose instances fail each other's identity checks.