Interview Prep Guide
Node.js Interview Questions and Answers for Freshers to Experienced Developers
Prepare for Node.js interviews with practical questions about runtime basics, Express, async behavior, architecture, and coding rounds.
Basic Node.js Interview Questions
What is Node.js?
Node.js is a JavaScript runtime built on Chrome V8 that lets developers run JavaScript outside the browser, especially for servers, tools, and APIs.
What is the event loop in Node.js?
The event loop is the mechanism that coordinates async callbacks, timers, I/O completion, and other queued work without blocking the main JavaScript thread.
What is package.json used for in a Node.js project?
package.json describes the project, its dependencies, scripts, entry points, and metadata so tooling knows how to install and run it.
What is the difference between module.exports and exports?
module.exports is the actual object being returned, while exports is just a reference to module.exports by default.
What is the difference between require() and import (ES modules)?
require() is used in CommonJS and is synchronous, while import is the standard ES module syntax that is asynchronous and supports static analysis.
Medium Node.js Interview Questions
What is middleware in Express?
Middleware is a function that sits in the request-response pipeline and can read, modify, validate, or terminate the request before the final handler responds.
How do you handle asynchronous errors in Node APIs?
Use consistent async patterns, catch promise rejections, propagate errors to centralized handlers, and avoid leaving unhandled exceptions or partial responses.
What is the difference between blocking and non-blocking I/O in Node.js?
Blocking I/O waits for an operation to finish before moving on, while non-blocking I/O lets Node continue handling other work and later process the result through callbacks, promises, or async-await.
What is a Buffer in Node.js and when should you use it?
A Buffer is a way to handle raw binary data in memory, mainly used for reading files, network communication, or image processing.
What is the purpose of the libuv library in Node?
libuv is a multi-platform C library that provides Node with asynchronous I/O capabilities, file systems access, and the internal thread pool.
Advanced Node.js Interview Questions
How do streams help performance in Node.js?
Streams process data in chunks, which reduces memory pressure and improves throughput when working with large files, uploads, downloads, or proxying data.
How would you scale a Node.js service in production?
Scale by reducing bottlenecks, using process-level or container-level replication, moving CPU-heavy work away from the main request path, and designing stateless service behavior where possible.
How would you handle graceful shutdown in a Node.js service?
Stop accepting new work, finish or cancel in-flight requests safely, close external connections, and exit only after cleanup or timeout.
What is the difference between Worker Threads and Multi-processing in Node?
Multi-processing creates entirely new Node processes with their own memory, while Worker Threads share the same memory heap using ArrayBuffers.
What are Event Emitters and where are they used?
Event Emitters are objects that trigger named events which other parts of the code can listen to, facilitating a decoupled, observer-style pattern.
Scenario-Based Node.js Interview Questions
How would you handle a Node.js API that starts timing out during traffic spikes even though the business logic has not changed?
Break the problem into event-loop pressure, slow downstream calls, database load, payload size, and concurrency behavior, then fix the real bottleneck rather than scaling blindly.
Node.js Coding Round
Build an Express endpoint with validation and error handling
A strong implementation validates input early, keeps business logic separate from the route body, and routes errors into one consistent handler. Better solutions also avoid duplicated response branches and include basic logging or trace context.
Implement a Simple Custom Middleware for Logging and Timing
This tests the absolute basics of Express. You should capture the start time at the top of the function, call next() , and then use res.on('finish', ... ) to calculate and log the final duration once the response is sent.
Implement a paginated REST endpoint with validation, error handling, and clean async flow
Interviewers usually look for predictable response shapes, safe validation, and clear async control flow. Strong answers explain how invalid inputs, empty results, and server failures are handled without leaking internal details.