All interview questions Web · 2026

Node.js Interview Questions

Node.js is one of the most common backend topics in web and full-stack interviews. These are the questions interviewers actually ask, with concise answers you can speak confidently.

17 questions with concise, interview-ready answers.

1. What is Node.js?

Node.js is a runtime that lets you run JavaScript outside the browser, built on Chrome's V8 engine. It uses an event-driven, non-blocking I/O model, which makes it lightweight and efficient for I/O-heavy and real-time applications. It ships with a large standard library and the npm ecosystem for building servers, tools, and APIs.

2. Is Node.js single-threaded?

The JavaScript execution and the event loop run on a single main thread, so your code runs one operation at a time. However, Node is not entirely single-threaded — libuv maintains a background thread pool that handles file I/O, DNS, and some CPU-bound work, and the OS handles network I/O asynchronously. This lets a single thread manage thousands of concurrent connections.

3. What does non-blocking I/O mean in Node.js?

Non-blocking I/O means an I/O operation (reading a file, querying a database, making a network call) is started and then control returns immediately to the program instead of waiting for the result. When the operation finishes, a callback or promise is scheduled to run. This lets the single main thread keep handling other requests instead of sitting idle, which is the core of Node's scalability.

4. What is the event loop in Node.js?

The event loop is the mechanism that lets Node perform non-blocking I/O on a single thread by offloading operations and processing their callbacks when they complete. It continuously checks queues of pending callbacks and executes them in phases. It is provided by libuv and is what allows Node to handle concurrency without spawning a thread per request.

5. What are the phases of the event loop?

Each iteration (tick) of the loop runs through ordered phases: timers (setTimeout/setInterval callbacks), pending callbacks (some deferred system callbacks), idle/prepare (internal), poll (retrieves new I/O events and runs their callbacks), check (setImmediate callbacks), and close callbacks (e.g. socket close events). Between phases, the microtask queue — process.nextTick and resolved promises — is drained.

6. What is libuv?

libuv is the C library that gives Node its asynchronous, event-driven capabilities. It implements the event loop, the thread pool, and a consistent abstraction over OS-level async I/O (epoll on Linux, kqueue on macOS, IOCP on Windows). When you do async file or network operations in Node, libuv is doing the underlying work.

7. What is the difference between callbacks, promises, and async/await?

Callbacks are functions passed to be invoked when an async operation finishes, but nesting them leads to hard-to-read code. Promises represent a future value and can be chained with .then()/.catch(), flattening that nesting. Async/await is syntactic sugar over promises that lets you write asynchronous code in a synchronous-looking style using try/catch for errors, and it is the modern preferred approach.

8. What is callback hell and how do you avoid it?

Callback hell is deeply nested callbacks — the "pyramid of doom" — that occurs when multiple asynchronous operations depend on each other, making code hard to read and maintain. You avoid it by using promises with chaining, async/await for flat sequential code, or named functions and modularization instead of inline anonymous callbacks.

9. What is the difference between CommonJS (require) and ES Modules (import)?

CommonJS uses require() and module.exports, loads modules synchronously, and is the traditional Node module system. ES Modules use import/export, are loaded asynchronously, support top-level await and static analysis, and are the standard JavaScript module format. You opt into ESM with "type": "module" in package.json or the .mjs extension.

10. What is the difference between process.nextTick and setImmediate?

process.nextTick() schedules a callback to run immediately after the current operation completes, before the event loop continues to the next phase — it runs in the microtask queue. setImmediate() schedules a callback to run in the check phase of the next event loop iteration. So process.nextTick fires sooner; overusing it can starve the I/O phases and block the loop.

11. What are streams in Node.js?

Streams are objects for reading or writing data piece by piece instead of loading it all into memory at once, which is efficient for large files or network data. There are four types: Readable, Writable, Duplex (both), and Transform (modifies data as it passes). You commonly connect them with pipe(), for example streaming a file to an HTTP response.

12. What is middleware in Express?

Middleware are functions that have access to the request and response objects and the next function in the request-response cycle. They can run code, modify req/res, end the request, or call next() to pass control to the next middleware. They are used for tasks like logging, authentication, body parsing, and error handling, and run in the order they are registered.

13. How do you handle errors in Node.js?

For synchronous code and async/await, use try/catch blocks. For promises, use .catch(); for callbacks, follow the error-first convention where the first argument is the error. In Express, error-handling middleware with four arguments (err, req, res, next) centralizes errors, and you should also listen for uncaughtException and unhandledRejection as a last resort.

14. What is the difference between clustering and worker threads?

The cluster module forks multiple Node processes that share the same server port, letting you use all CPU cores by running separate instances with their own memory and event loop — good for scaling I/O-bound servers. Worker threads run JavaScript in parallel threads within a single process and can share memory, which is better suited for CPU-intensive tasks without blocking the main event loop.

15. What is package.json and what is npm?

package.json is the manifest file that describes a Node project — its name, version, scripts, and dependencies. npm (Node Package Manager) is the default tool and registry for installing, publishing, and managing those dependencies. Running npm install reads package.json, fetches the packages, and records exact versions in package-lock.json for reproducible installs.

16. What is the difference between blocking and non-blocking code?

Blocking code stops the execution of further JavaScript until the current operation completes, occupying the single main thread (for example, fs.readFileSync). Non-blocking code starts the operation and continues executing, handling the result later via a callback or promise (for example, fs.readFile). Because Node runs on one thread, blocking operations hurt throughput, so non-blocking APIs are preferred for I/O.

17. What is the EventEmitter in Node.js?

EventEmitter is a core class (from the events module) that implements the publish-subscribe pattern. Objects emit named events with emit(), and listeners registered with on() or once() respond to them. Many built-in Node objects — streams, HTTP servers, and processes — inherit from EventEmitter, making it central to Node's event-driven architecture.

Get these answered live in your real interview

NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.

Try NostrobeAI free