Key Node.js interview questions for backend and full-stack roles, covering the event loop, streams, error handling, and scaling — each with a concise answer. Then practice explaining them in a live mock.
Node.js is a JavaScript runtime built on V8 for server-side code. It uses a single-threaded, non-blocking event loop with asynchronous I/O, so it handles many concurrent connections efficiently.
CommonJS is synchronous and uses module.exports/require; ES modules use import/export, are statically analyzable, and support top-level await. Node supports both — .mjs or "type":"module" selects ESM.
It runs in phases (timers, pending callbacks, poll, check, close). Microtasks — promises and process.nextTick — run between phases, and blocking I/O is offloaded to libuv's thread pool.
Blocking code halts the event loop until it finishes (e.g. fs.readFileSync), starving other requests; non-blocking code uses callbacks or promises so the loop keeps serving work. Avoid blocking calls in request handlers.
Streams process data in chunks instead of loading it all into memory — Readable, Writable, Duplex, and Transform. They're ideal for large files or network data and are composed with .pipe().
Use try/catch with async/await, .catch() on promises, error-first callbacks, and 'error' events on streams and emitters. Always handle unhandled promise rejections so the process doesn't crash silently.
Middleware are functions with (req, res, next) that run in order to process a request — parsing bodies, auth, logging — calling next() to pass control or ending the response themselves.
nextTick callbacks run right after the current operation, before the loop continues; setImmediate runs on the next iteration's check phase. Overusing nextTick can starve I/O.
Node is single-threaded per process, so use the cluster module or worker_threads, or run multiple processes behind a load balancer (e.g. with PM2) to use all cores.
dependencies are needed at runtime in production; devDependencies are only for development and builds (test runners, bundlers, linters). npm install --production skips devDependencies.
Reading answers is one thing — saying them under pressure is another. Run a free AI mock interview and get scored feedback.
Start a mock interview