Node.js Interview Questions and Answers
100 Node.js interview questions across 10 topics: Node.js Core & Event Loop, Async Programming & Timers, Buffers & Streams, Modules, ESM & Package Management, HTTP, Fastify & Web Frameworks, Databases, ORMs & Transactions, Security & Best Practices, Performance & Memory Profiling, Testing & Quality Assurance, and Microservices & Distributed Systems. They cover Mid-level, Senior, and Junior levels, and every question has a short answer to give in the interview, a deeper explanation, common mistakes, and links to official documentation with a last-reviewed date.
Topics
Node.js Core & Event Loop
10 questions
Async Programming & Timers
10 questions
Buffers & Streams
10 questions
Modules, ESM & Package Management
10 questions
HTTP, Fastify & Web Frameworks
10 questions
Databases, ORMs & Transactions
10 questions
Security & Best Practices
10 questions
Performance & Memory Profiling
10 questions
Testing & Quality Assurance
10 questions
Microservices & Distributed Systems
10 questions
Node.js Core & Event Loop Interview Questions (Node.js)
- What are the basic phases of the event loop in Node.js and how does it handle different tasks?
- What is the essential difference between process.nextTick() and setImmediate() in Node.js?
- What is the role of the libuv library and the internal thread pool in Node.js and when is it used?
- How does the V8 engine manage memory between the stack and the heap in Node.js?
- What does it mean that Node.js is single-threaded and how does it handle thousands of concurrent connections?
- What is the difference between uncaughtException and unhandledRejection in Node.js and what is the right action when they occur?
- How do you design a graceful shutdown mechanism in a Node.js app when receiving SIGTERM or SIGINT signals?
- How does EventEmitter work in Node.js and what causes the MaxListenersExceededWarning?
- How is AbortController used to cancel asynchronous operations in modern Node.js?
- What are native addons and Node-API (N-API) and when does a developer resort to building them?
Async Programming & Timers Interview Questions (Node.js)
- What is the practical difference between using async/await and dealing directly with promises in Node.js?
- Compare Promise.all, Promise.allSettled, and Promise.race in Node.js in terms of behavior and error handling.
- Why is running hundreds of promises through Promise.all dangerous and how do you apply concurrency limiting?
- What is the AsyncLocalStorage technique in Node.js and what problems does it solve in request tracing?
- How does the priority of microtasks differ from macrotasks in task processing in Node.js?
- How do errors travel in asynchronous code and what is the danger of errors inside traditional callbacks?
- What is the event loop starvation phenomenon caused by CPU-intensive tasks and how do you avoid it?
- What is the top-level await feature in ES modules in Node.js and what are the cautions of using it?
- How do async iterators and the for await...of loop help consume data streams in Node.js?
- What is the concept of async disposable resources and the Symbol.asyncDispose symbol?
Buffers & Streams Interview Questions (Node.js)
- What are the four types of streams in Node.js and what is the function of each?
- What is the backpressure phenomenon in Node.js streams and how is it handled in engineering terms?
- Why is it always recommended to use stream.pipeline instead of traditional chaining through .pipe()?
- What is the Buffer object in Node.js and how does Buffer.alloc allocation differ from Buffer.allocUnsafe?
- What is the role of the highWaterMark option in streams and how does it affect memory efficiency and performance?
- How do you design large file uploads as streams in an HTTP server without storing the file in memory?
- How do you create and customize a Transform Stream to process data as it flows through Node.js?
- When should you use fs.readFile, and when should you prefer fs.createReadStream for working with files?
- What is Object Mode in Node.js Streams, and when should it be enabled?
- How do you close Streams manually with .destroy(), and why is it important to handle error events?
Modules, ESM & Package Management Interview Questions (Node.js)
- Compare CommonJS (CJS) and ES Modules (ESM) in Node.js. How does the runtime handle them?
- What is the 'exports' field in package.json, and how does it improve on the older 'main' field?
- How does Node.js handle circular dependencies between CJS and ESM?
- What is the difference between npm install and npm ci, and why is package-lock.json important?
- How do npm/pnpm Workspaces manage monorepos, and what are their benefits?
- What is the Dual Package Hazard when publishing a library that supports both CJS and ESM in Node.js?
- How do you use Node.js's built-in test runner (node:test) without external libraries?
- What do the ^ and ~ symbols mean in package.json, and how do they differ from an exact version?
- Why is the node: prefix useful when importing built-in modules such as node:fs and node:path?
- How does modern Node.js support running TypeScript files directly with Type Stripping?
HTTP, Fastify & Web Frameworks Interview Questions (Node.js)
- How does the built-in HTTP server (node:http) work, and what is the lifecycle of IncomingMessage and ServerResponse objects?
- How do Express Middlewares work, and how does Regular Middleware differ from Error-Handling Middleware?
- Why can Fastify outperform traditional frameworks, and how does Schema-Based Compilation work?
- How does NestJS apply Dependency Injection and organize Modules?
- Why is input validation with schema libraries such as Zod important in Node.js?
- What is Content Negotiation, and how do you handle the Accept and Content-Type headers?
- How do you build an efficient WebSocket server with the ws library and implement a Heartbeat (Ping/Pong)?
- How do you safely handle multipart/form-data requests and file uploads in Node.js servers?
- How do you protect a Node.js server from Slowloris attacks and implement request rate limiting (Rate Limiting)?
- When should you prefer Server-Sent Events (SSE) over WebSockets, and how do you implement SSE in Node.js?
Databases, ORMs & Transactions Interview Questions (Node.js)
- How do database Connection Pools work, and what are the risks of exhausting them in Node.js?
- How does Prisma ORM work in Node.js, and what role does its Query Engine / Query Compiler play?
- Compare Drizzle ORM and TypeORM in terms of architecture and performance in Node.js.
- How does Mongoose manage its MongoDB connection, and what is the role of command Buffering?
- How do parameterized queries protect Node.js applications from SQL Injection?
- How do you safely implement Database Transactions and isolation levels in Node.js?
- What is the N+1 problem in database queries, and how does DataLoader solve it in Node.js?
- How do you design query routing between a Primary database and Read Replicas?
- How do you perform Database Migrations without service downtime (Zero-Downtime)?
- How do you implement Distributed Locks with Redis across multiple Node.js servers?
Security & Best Practices Interview Questions (Node.js)
- How do symmetric (HS256) and asymmetric (RS256) signing algorithms differ for JWTs in Node.js?
- How do you implement Refresh Token Rotation and secure storage in cookies?
- Why should you never use SHA-256 functions to hash passwords, and why are Argon2 or bcrypt preferred?
- How do Cross-Site Request Forgery (CSRF) attacks work, and how do you protect Node.js applications from them?
- What is Cross-Origin Resource Sharing (CORS), and what are Preflight Requests?
- What is the Helmet package, and which essential security headers does it add to a Node.js application?
- What is JavaScript Prototype Pollution, and how do you avoid it in Node.js?
- How do you manage environment variables and Secrets safely in Node.js projects?
- What are Timing Attacks, and why should crypto.timingSafeEqual be used to compare sensitive tokens?
- How do you protect a Node.js project from Supply Chain Attacks in the npm ecosystem?
Performance & Memory Profiling Interview Questions (Node.js)
- How do you use multiple CPU cores with Node.js's node:cluster module?
- How do Worker Threads differ from Child Processes in Node.js?
- How do you detect and diagnose Memory Leaks with Heap Snapshots in Node.js?
- How do you use Flamegraphs to diagnose performance and CPU bottlenecks in Node.js?
- Why should you enable keepAlive in HTTP clients (node:http Agent) when calling external services?
- How do you implement the Cache-Aside pattern and Cache Invalidation strategies?
- How do you configure --max-old-space-size, and when should you change V8 Garbage Collector options?
- Why can JSON.stringify become a performance bottleneck in large services, and what are its optimized alternatives?
- What is Threadpool Starvation, and how do you configure UV_THREADPOOL_SIZE to avoid it?
- How does the PM2 process manager help manage Node.js servers in production, and what is Zero-Downtime Reload?
Testing & Quality Assurance Interview Questions (Node.js)
- How do you write robust unit tests for asynchronous functions and check for rejected promises in Node.js?
- How do you use Supertest to test HTTP endpoints without binding the server to a real network port?
- How do you isolate external services in integration tests with libraries such as nock or MSW?
- What are the benefits of using Testcontainers to test real databases in Node.js projects?
- How do you test that operations remain correct under Race Conditions and balance conflicts?
- What is Contract Testing with Pact between Node.js microservices?
- What role do end-to-end (E2E) tests play in backend systems, and when are they useful?
- Why is 100% Code Coverage not sufficient evidence of test quality, and what is Mutation Testing?
- How do you reliably test Streams and EventEmitters in Node.js tests?
- What causes Flaky Tests, and how do you make tests deterministic (Determinism)?
Microservices & Distributed Systems Interview Questions (Node.js)
- How do you apply Clean Architecture and separation of concerns in a Node.js application?
- How do Message Queues such as BullMQ help process complex background tasks?
- How do Consumer Groups work in Apache Kafka with Node.js servers?
- Compare gRPC and REST for communication between Node.js microservices (Microservices).
- What is the Circuit Breaker pattern, and how does it prevent Cascading Failures?
- How do you implement Distributed Tracing in Node.js with the OpenTelemetry standard?
- Why prefer Structured JSON Logging with libraries such as Pino over console.log?
- What is the key difference between Liveness Probe and Readiness Probe in Kubernetes for Node.js applications?
- What are the security and performance best practices for building Docker containers for Node.js applications?
- How do you design Idempotent Consumers in distributed Node.js systems?