89 Node.js interview questions with answers
89 Node.js interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Node.js interview questions
What is Node.js? How does it differ from JavaScript in the browser?
What is the V8 engine? What role does it play in Node.js?
What does event-driven architecture mean in Node.js?
What is non-blocking I/O in Node.js? Why is it important?
What is npm? What is the difference between npm install and npm install --save-dev?
What is package.json? What are its important fields?
What is package-lock.json? Why should you commit this file?
How do CommonJS modules (require/module.exports) and ES Modules (import/export) differ in Node.js?
What does the process object provide in Node.js?
What is the difference between __dirname and __filename in Node.js?
How does the event loop work in Node.js?
What is the difference between setTimeout(fn, 0) and setImmediate()?
How does process.nextTick() differ from setImmediate()?
What is callback hell? How do you solve it?
How do Promises work in Node.js? What are the states of a Promise?
What is async/await in Node.js? What are its advantages over Promise chains?
What are Streams in Node.js? What types of streams exist?
What is a Buffer in Node.js? When do you need to use it?
What is libuv? What role does it play in Node.js?
How do you create an HTTP server using Node.js's http module?
What is Express.js? Why is it so popular in the Node.js ecosystem?
What is middleware in Express? How does it work?
What is a Router in Express? How do you organize routes?
REST API in Express: how do you define HTTP methods?
How does error handling middleware work in Express?
CORS in Express: how do you configure it to allow cross-origin requests?
What do express.json() and express.urlencoded() middleware do?
What is rate limiting in Express? How do you implement it?
What are the differences between Express 4 and Express 5?
What is JWT (JSON Web Token)? What is the structure of a JWT?
How do you implement JWT authentication in an Express API?
What is bcrypt? How do you use it to hash passwords?
How are access tokens and refresh tokens different?
What is clustering in Node.js? Why is it necessary?
What are Worker Threads in Node.js? How do they differ from Cluster?
Microservices architecture with Node.js: what are the pros and cons?
Caching in a Node.js API: what are the common strategies?
How do you handle unhandled Promise rejections in Node.js?
fs module in Node.js: how do fs.readFile and fs.createReadStream differ?
What is the difference between fs.readFile and fs.readFileSync?
Environment variables in Node.js: how do you use them and why are they important?
What is event loop blocking in Node.js? How do you avoid it?
What is backpressure in Node.js streams? Why is it important?
How do you debug a Node.js application?
What is an EventEmitter in Node.js? How do you use it?
What are common security vulnerabilities in a Node.js API and how do you prevent them?
What is graceful shutdown in Node.js? Why is it important?
How do you write unit tests for a Node.js API with Jest?
What is PM2? Why use it in production?
What is Node.js? Why use it for backend development?
What is a REST API? What principles should you follow when designing one?
How do you handle file uploads in Node.js?
What are Streams in Node.js? Why use Streams instead of reading the full file?
How do process.env and dotenv work?
What do you use for input validation in Express?
What are the caching strategies for a Node.js API?
What is the error handling strategy for a production Node.js app?
What are the logging best practices for Node.js in production?
How do you use WebSockets with Socket.io in Node.js?
What are the microservices communication patterns?
Node.js is single-threaded. Why can it still handle multiple requests? Explain the event loop.
Callback vs Promise vs async/await. How do you handle errors in each?
What are environment variables in Node.js? Why are they needed? What about .env files?
Child processes in Node.js: how do `spawn()`, `fork()`, and `exec()` differ?
What is the reactor pattern in Node.js, and how does it underpin the event loop?
What are the weaknesses of Node.js? When should you NOT use it?
What does Node.js's `crypto` module provide? (hashing, HMAC, ciphers)
What is stream piping with `.pipe()` in Node.js, and how does it relate to backpressure?
Session management in Node.js: how does `express-session` differ from JWT?
How do `Buffer.alloc`, `Buffer.allocUnsafe`, and `Buffer.from` differ? Why is `allocUnsafe` considered risky?
What causes `ERR_REQUIRE_ESM` or `Cannot use import statement outside a module`, and how do you fix it?
Production logs show `MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 listeners added` — what does it mean and how do you fix it?
What is the libuv thread pool? Which Node APIs use it and which do not? What does `UV_THREADPOOL_SIZE` change?
Why prefer `stream.pipeline()` over chained `.pipe()` calls?
You need to import a 2GB CSV file into a database. How would you design the flow so it does not run out of memory?
What problem does `AsyncLocalStorage` solve? How would you use it to attach a request id to logs?
A Node service on Kubernetes still returns 502s during rolling updates even though it handles `SIGTERM` and calls `server.close()`. Why, and how do you fix it?
Since Node 15, what happens when a promise rejects with no handler? How should you deal with `unhandledRejection` and `uncaughtException` in production?
A CPU-heavy endpoint (image resizing, exporting 200k rows to Excel) stalls the whole API. How do you weigh `worker_threads`, `cluster`, `child_process`, and a job queue?
A Node service grows in RSS and gets OOM-killed after a few days. How do you investigate with heap snapshots?
How expensive is passing data between the main thread and `worker_threads`? How do `transferList` and `SharedArrayBuffer` differ?
Why does middleware order matter in Express, and why does middleware declared after a route never run?
What is the difference between `next()`, `next(err)` and `next('route')` in Express?
Why can't `express.json()` read a file upload? How do you handle `multipart/form-data`?
Why must an Express error-handling middleware declare all four parameters?
In Express 4 an `async` handler that throws never reaches the error middleware — why? What changed in Express 5?
What causes `ERR_HTTP_HEADERS_SENT` — "Cannot set headers after they are sent to the client" — and how do you fix it?
With nested Express routers, why is `req.params.userId` undefined in the child router, and how do you fix it?
How would you design a multi-gigabyte file upload flow in Node.js without exhausting memory?