Interview Q&A · questions with model answers
Node.js Developer Interview Questions
Part of the study plan for: Full Stack Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Explain the phases of the Node.js event loop.
Each loop iteration runs these phases in order: timers (setTimeout/setInterval callbacks), pending callbacks (some system errors), idle/prepare (internal), poll (retrieve new I/O events and run I/O…
-
Most asked How has asynchronous code evolved in Node.js: callbacks, Promises and async/await?
Node started with error-first callbacks ((err, data) => {}), moved to Promises (chainable, composable) and now favors async/await on top of Promises, with promise-based core APIs like fs/promises,…
-
Most asked How does middleware work in Express?
Middleware are functions (req, res, next) executed in registration order; each can modify req/res, end the response, or call next() to pass control. Error-handling middleware has four arguments…
-
Most asked How do you work with relational databases efficiently in Node.js?
Use a connection pool (pg.Pool, mysql2 pools) shared across requests, parameterized queries, transactions with proper release in finally, and an ORM or query builder (Prisma, Drizzle, Kysely,…
-
Most asked Walk through how an Express app handles a request, including errors from async handlers.
Middleware and routes run in registration order; each either responds or calls next(). next(err), or a synchronous throw, skips to error-handling middleware, which Express recognises by its four…
-
Most asked How should errors be handled in a Node.js application?
Use try/catch with async/await, always handle promise rejections, pass errors to framework error handlers (e.g., Express next(err)), distinguish operational errors (timeouts, invalid input) from…
-
Most asked How do you scale a Node.js application?
Scale vertically by using all cores (cluster/PM2 or multiple containers) and horizontally by running many stateless instances behind a load balancer, with shared state in Redis/databases, caching…
-
How should configuration and secrets be managed in Node.js?
Read configuration from environment variables, validate and type them at startup (Zod, envalid), load .env files only in development (Node 20.6+ supports --env-file natively), and keep secrets in a…
-
How do `AbortController` and `AbortSignal` work in Node?
An AbortController produces a signal you pass to cancellable APIs (fetch, timers/promises, fs, streams, child processes, events.once); calling controller.abort(reason) cancels them, rejecting with…
-
Explain semantic versioning ranges like `^1.2.3` and `~1.2.3`.
Semver is MAJOR.MINOR.PATCH. ^1.2.3 allows >=1.2.3 <2.0.0 (compatible minor/patch updates), ~1.2.3 allows >=1.2.3 <1.3.0 (patch updates), and an exact 1.2.3 pins the version. For 0.x versions,…
-
How does Node.js's release schedule work, and which versions should production use?
Even-numbered major releases become Long-Term Support (LTS) and receive about 30 months of support (Active, then Maintenance); odd-numbered releases are short-lived 'Current' releases. Production…
-
How do you handle large file uploads in Node.js?
Stream multipart uploads with busboy/multer (or Fastify multipart) directly to disk or object storage instead of buffering in memory, enforce size and type limits, and consider presigned URLs so…
-
How does V8's garbage collector work, and how does it affect Node apps?
V8 uses a generational GC: short-lived objects are allocated in the young generation and collected quickly by a scavenger, while survivors are promoted to the old generation, collected by…
-
How do Node.js microservices communicate reliably?
Synchronously via HTTP/gRPC with timeouts, retries (for idempotent calls) and circuit breakers, or asynchronously via message brokers (Kafka, RabbitMQ, SQS/SNS, NATS) with at-least-once delivery,…
-
What happens to other requests when one request blocks the Node.js event loop?
They all wait. Node runs JavaScript for every request on one event-loop thread per process, switching only when code yields (awaits I/O, callbacks). A synchronous CPU-heavy loop, a sync file or…
-
How should a Node.js process exit, and why prefer `process.exitCode` over `process.exit()`?
Set process.exitCode = 1 and let the event loop drain naturally so pending writes (logs, stdout) flush; process.exit() terminates immediately and can truncate output or skip cleanup.
-
How does Node resolve packages, and what does the `exports` field do?
Node looks up node_modules directories from the current folder upward; inside a package, the exports field defines the public entry points (including subpaths and conditions like import, require,…
-
How can large JSON payloads hurt Node.js performance, and what are alternatives?
JSON.parse and JSON.stringify are synchronous and block the event loop for large payloads (multi-MB), causing latency spikes for all requests. Alternatives: paginate, stream JSON (NDJSON, stream…
-
How does module caching work in Node.js?
Modules are evaluated once and cached (CommonJS in require.cache, ESM in the module map), so subsequent imports return the same instance, which is why a module can act as a singleton.
-
How do you handle dates and timezones correctly in Node.js?
Store and transmit timestamps in UTC (ISO 8601), convert to user time zones only for display using Intl.DateTimeFormat or libraries like date-fns-tz/Luxon, and set TZ=UTC on servers to avoid…
-
How does Fastify's plugin system and encapsulation work?
Everything in Fastify is a plugin registered with fastify.register(). Each plugin gets its own encapsulated context, so decorators, hooks and routes added inside don't leak to siblings unless the…
-
Describe NestJS's core building blocks.
NestJS organizes apps into modules containing controllers (routing), providers/services (business logic) injected via its DI container, plus pipes (validation/transformation), guards…
-
Does Node.js support HTTP/2 and when would you use it directly?
Yes, via the node:http2 module (with TLS for browsers). It offers multiplexing, header compression and server push (deprecated by browsers). Most deployments let a proxy/CDN handle HTTP/2 or HTTP/3…
-
How are feature flags used in Node.js services?
Feature flags (LaunchDarkly, Unleash, OpenFeature-compatible providers, or simple config) toggle behavior at runtime for gradual rollouts, A/B tests and kill switches without redeploying.
-
How does the `cluster` module distribute connections, and why might you need sticky sessions?
The primary process forks workers and (on most platforms) distributes incoming connections round-robin. Protocols that keep state in a worker's memory (e.g., Socket.IO with long-polling) need sticky…