Node.js Interview Questions and Answers

Node.js interviews revolve around one idea: a single thread running an event loop. You are expected to explain the phases of the loop, the difference between process.nextTick, microtasks and timers, why blocking the loop is dangerous, and how callbacks, promises and async/await relate.

Beyond the loop, expect streams and backpressure, the cluster and worker-thread modules, memory leaks, error handling in async code, security basics (injection, rate limiting, dependency risk) and how you would structure and scale an Express or Fastify service. The answers below include runnable examples.

Questions

Related

Frequently asked questions

What is the event loop in Node.js?

It is the mechanism that lets a single thread handle many connections: it runs callbacks from queues in phases (timers, pending, poll, check, close) and drains microtasks between them, handing slow work to the operating system or a thread pool.

When should I use worker threads or cluster?

Use cluster to run several processes that share a port and use all CPU cores for I/O-heavy servers. Use worker threads for CPU-heavy work inside one process so the event loop is not blocked.

What Node.js topics are asked at senior level?

Scaling and observability, memory leaks and profiling, streams and backpressure, graceful shutdown, security hardening and designing resilient services.