HomeInterview QuestionsNode.js Interview QuestionsTop 10
🟢
Free Study Guide · 2025

Top 10 Node.jsInterview Questions & Answers (2025)

Node.js powers the backend of most modern Indian startups — Razorpay, CRED, Meesho, and dozens of others. These questions cover the event loop, async patterns, Express, streams, and system design concepts you'll face in backend JavaScript roles.

10 questions
Detailed answers
100% free
Also available:Top 20All 20 questions →
1What is Node.js and what makes it non-blocking?
Node.js is a JavaScript runtime built on Chrome's V8 engine that executes JavaScript outside the browser. It's non-blocking because it uses an event-driven, single-threaded architecture with an event loop that delegates I/O operations to the operating system's asynchronous APIs (via libuv). While I/O waits, the event loop handles other requests, making Node excellent for I/O-bound concurrent workloads.
2How does the Node.js event loop work?
The event loop processes tasks in phases: timers (setTimeout/setInterval callbacks), pending callbacks (I/O errors), idle/prepare, poll (wait for new I/O, execute callbacks), check (setImmediate callbacks), close callbacks. Microtasks (process.nextTick and Promises) run between phases. process.nextTick runs before any I/O — even before Promises.
3What is the difference between process.nextTick() and setImmediate()?
process.nextTick() queues a callback to run after the current operation completes but before the event loop continues to the next phase — it has the highest priority among async callbacks. setImmediate() runs in the check phase, after the poll (I/O) phase. In practice: nextTick runs before Promises; setImmediate runs after I/O callbacks in the current loop iteration.
4What is the CommonJS module system in Node.js?
CommonJS is Node.js's original module system using require() to import and module.exports or exports to export. Modules are cached after first load. Node.js also supports ES Modules (import/export) in .mjs files or when type: 'module' is set in package.json. The two systems are not interoperable without adapters — mixing them in the same project requires care.
5What are streams in Node.js?
Streams are abstract interfaces for working with streaming data, enabling processing of large files or network data without loading everything into memory. Four types: Readable (fs.createReadStream), Writable (fs.createWriteStream), Duplex (readable + writable, like a TCP socket), and Transform (modify data in transit, like zlib.createGzip). Streams use events: data, end, error, finish.
6What is the difference between spawn(), exec(), and fork() in child_process?
spawn() launches a new process and streams stdin/stdout — ideal for long-running commands producing large output. exec() runs a command in a shell and buffers the entire output — suitable for small, quick commands. fork() is a special spawn for Node.js modules — it creates a new Node.js process with a built-in IPC (message-passing) channel between parent and child.
7What is clustering in Node.js and why do you use it?
Node.js is single-threaded, so it can't natively use multiple CPU cores. The cluster module lets you spawn multiple child processes (workers) that all share the same server port. The master process distributes incoming connections to workers. A common pattern: spawn os.cpus().length workers. PM2 manages clustering in production with zero-downtime restarts.
8What is the EventEmitter in Node.js?
EventEmitter is a core Node.js class for implementing the observer pattern. Objects extend EventEmitter to emit named events (emitter.emit('event', data)) and register listeners (emitter.on('event', callback)). Most Node.js core APIs (streams, http, etc.) extend EventEmitter. Common pitfalls: forgetting to remove listeners (memory leaks) and unhandled 'error' events crashing the process.
9What is middleware in Express.js?
Middleware are functions in Express's request-response cycle with access to (req, res, next). They can execute code, modify req/res, end the request, or call next() to pass control to the next middleware. Used for: logging, auth checks, request parsing (express.json()), CORS headers, error handling. Error-handling middleware has four parameters: (err, req, res, next).
10How do you handle errors in Node.js?
Synchronous: try-catch. Async (callbacks): check the first argument (err-first convention). Promises: .catch() or try-catch in async/await. Add a global process.on('unhandledRejection') and process.on('uncaughtException') as last-resort handlers. In Express, use a 4-parameter error-handling middleware. Always log errors with context and avoid silently swallowing them.
See all 20 Node.js questions →
Level up your prep
Get company-specific Node.js questions
Upload your resume → get questions tailored to Google, Amazon, TCS, and 50+ companies.
Try AI Interview Prep →
© 2025 CareerLens · Home · Interview Questions · Pricing