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.

  1. Most asked How do you implement graceful shutdown in a Node.js server?

    On SIGTERM/SIGINT, stop accepting new connections (server.close()), let in-flight requests finish (with a timeout), close keep-alive connections, stop consumers, close DB pools and other resources,…

  2. Most asked What causes memory leaks in Node.js and how do you diagnose them?

    Common causes: unbounded caches or global arrays, event listeners never removed, closures holding large objects, timers/intervals never cleared, and growing queues of unprocessed work. Diagnose with…

  3. Most asked How would you implement authentication in a Node.js API?

    Choose sessions (server-side store + HttpOnly cookie) for browser apps or tokens (short-lived JWT access tokens + rotating refresh tokens) for APIs/mobile. Hash passwords with bcrypt/argon2, verify…

  4. Most asked What makes a well-designed REST API in Node.js?

    Resource-oriented URLs, correct HTTP methods and status codes, consistent JSON shapes and error format, pagination/filtering, validation, versioning, idempotency for retries,…

  5. Most asked How do you implement rate limiting in a Node.js API?

    Use middleware (express-rate-limit, @fastify/rate-limit) backed by Redis for multi-instance deployments, with algorithms like fixed window, sliding window or token bucket, keyed by API key, user ID…

  6. How do you profile CPU performance in a Node.js app?

    Use node --cpu-prof or --inspect with Chrome DevTools to record CPU profiles and flame graphs, tools like clinic.js (doctor, flame, bubbleprof) or 0x, and APM traces in production to find hot…

  7. How do you create an HTTP server with Node's core `http` module, and why use a framework instead?

    http.createServer((req, res) => { ... }).listen(3000) handles raw requests: you parse URLs, read bodies from the request stream, set headers and status, and end responses yourself. Frameworks add…

  8. How do you make HTTP requests in modern Node.js?

    Use the built-in global fetch (powered by undici, stable since Node 18/21), with AbortSignal.timeout(ms) for timeouts. For advanced needs (connection pooling control, interceptors, mocking), use…

  9. How should you log in a production Node.js service?

    Use a fast structured JSON logger such as Pino, with log levels, request-scoped child loggers that carry request IDs, redaction of sensitive fields, and output to stdout for collection by the…

  10. How do you test Node.js applications?

    Use a test runner (built-in node:test with node --test, or Vitest/Jest), test HTTP endpoints with supertest or the framework's inject API (Fastify inject), mock modules, timers and network…

  11. How do you reduce npm supply-chain risk?

    Commit lockfiles and use npm ci, review new dependencies (maintenance, popularity, install scripts), run npm audit/Socket/Snyk, enable automated updates with CI, disable or restrict lifecycle…

  12. How do you use Redis with Node.js for caching and coordination?

    Use a client like ioredis or node-redis for cache-aside caching with TTLs, distributed locks, rate limiting counters, sessions, pub/sub and queues (BullMQ), sharing one connection (or pool) per…

  13. How do you run background jobs in Node.js?

    Use a job queue such as BullMQ (Redis), pg-boss (Postgres), or managed services (SQS, Cloud Tasks): producers enqueue jobs, separate worker processes consume them with retries, backoff, concurrency…

  14. How do you validate request input in Node.js APIs?

    Validate bodies, params and query strings at the edge with a schema library (Zod, Joi, Ajv/JSON Schema, TypeBox), reject invalid input with 400/422 and field errors, and use parsed (typed, coerced)…

  15. How do you build real-time features with WebSockets in Node.js?

    Use the ws library (or uWebSockets.js) for raw WebSockets, or Socket.IO for rooms, reconnection and fallbacks. To scale across processes, use a pub/sub adapter (Redis) so messages reach clients…

  16. How do you prevent path traversal when serving files in Node.js?

    Resolve the requested path against a base directory with path.resolve, then verify the result still starts with the base directory (plus a separator) before reading; reject .. sequences, absolute…

  17. How do you add observability to a Node.js service?

    Instrument with OpenTelemetry (auto-instrumentation for HTTP, Express/Fastify, pg, Redis, etc.) for distributed traces and metrics, ship structured logs with trace IDs, and track event loop lag,…

  18. How do you schedule recurring jobs in a Node.js system?

    Use OS-level cron or Kubernetes CronJobs to run scripts, or queue-based repeatable jobs (BullMQ repeat, pg-boss schedules). In-process schedulers (node-cron) run once per instance, so they need…

  19. How do you size Node.js memory in containers?

    Set container memory limits and let Node derive heap limits (Node 20+ is container-aware), or set --max-old-space-size to about 75% of the container limit, leaving room for buffers, native modules…

  20. How do you debug a Node.js application?

    Run with node --inspect (or --inspect-brk) and attach Chrome DevTools or VS Code for breakpoints, stepping and profiling; use source maps for TypeScript; add structured logs; and use…

  21. How do you design liveness and readiness checks for a Node service?

    Liveness confirms the process is responsive (a trivial endpoint, optionally checking event loop lag); readiness verifies the instance can serve traffic (dependencies reachable, warm-up done) and…

  22. How do you do dependency injection in Node.js without a framework?

    Pass dependencies explicitly through factory functions or constructors (createUserService({ db, mailer })) and wire everything in one composition root at startup; tests pass fakes. Containers like…

  23. How do you build a CLI tool with Node.js?

    Add a bin entry in package.json pointing to a script with a #!/usr/bin/env node shebang, parse arguments with util.parseArgs or libraries (commander, yargs), use readline/prompts for interaction,…

  24. How do you detect and fix N+1 queries in Node ORMs?

    Enable query logging (Prisma log: ['query'], Sequelize/TypeORM logging) or APM spans to spot repeated similar queries, then use eager loading (include, with, joins), batch fetching (WHERE id IN…

  25. How do you format numbers, currencies and plurals for different locales in Node?

    Use the built-in Intl APIs: Intl.NumberFormat (currency, units), Intl.DateTimeFormat, Intl.PluralRules, Intl.RelativeTimeFormat and Intl.ListFormat. Node ships with full ICU data by default.

  26. How do you use MongoDB effectively from Node.js?

    Use the official driver or Mongoose (schemas, validation, middleware), share one client with a connection pool per process, design documents around access patterns, create indexes for queries, use…

  27. How do you organize routes in a larger Express app?

    Use express.Router() per feature, mounted with app.use('/users', usersRouter), keep handlers thin by delegating to services, apply route-specific middleware (auth, validation) at the router level,…

  28. How do you consume Kafka events reliably in Node.js?

    Use a client like KafkaJS or the Confluent client, join a consumer group, process messages idempotently (they may be redelivered), commit offsets only after successful processing, handle rebalances…

  29. How do you achieve zero-downtime deployments for Node services?

    Run multiple instances behind a load balancer and roll them gradually (rolling, blue-green or canary), with readiness checks, graceful shutdown that drains connections, and backward-compatible…

  30. How do you implement HTTP caching in Node.js APIs?

    Set Cache-Control headers appropriate to each resource (public/private, max-age, stale-while-revalidate), generate ETags (Express does weak ETags by default) and return 304 Not Modified for matching…

  31. How do you process a large log file line by line in Node.js?

    Create a read stream and use readline.createInterface({ input: stream, crlfDelay: Infinity }), then iterate with for await (const line of rl), which keeps memory flat regardless of file size.

Was this page helpful?

Report a mistake