Node.js is the backbone of backend development at hundreds of Indian startups and product companies. Whether you are applying to a Series A startup or a mid-size product company, Node.js interview questions test both your theoretical understanding of JavaScript's runtime model and your practical ability to build scalable APIs. This guide covers the most asked questions with clear, interview-ready answers.
Core Node.js concepts most commonly tested
Event Loop: The single most important Node.js concept in interviews. The event loop is what allows Node.js to perform non-blocking I/O despite being single-threaded. It has multiple phases: timers (setTimeout/setInterval callbacks), pending callbacks, idle/prepare, poll (I/O events), check (setImmediate callbacks), and close callbacks. Understanding why setTimeout(fn, 0) and setImmediate(fn) behave differently is a common interview follow-up.
Callback Hell and Solutions: Early Node.js code used deeply nested callbacks. Modern Node.js uses: Promises (.then/.catch), async/await (syntactic sugar over Promises), and libraries like async.js for concurrency control. Know how to refactor a callback pyramid into async/await.
Event Emitter: Node's built-in publish-subscribe mechanism. Used internally by streams, HTTP, and filesystem modules. Know how to create a custom EventEmitter, add listeners, emit events, and remove listeners to prevent memory leaks.
Streams: Readable, Writable, Duplex, and Transform streams. Critical for handling large files and data without loading them entirely into memory. pipe() chains streams efficiently. Common interview question: 'How would you process a 10GB CSV file in Node.js without running out of memory?'
Top 15 Node.js interview questions with answers
Q1: What is the difference between process.nextTick() and setImmediate()? process.nextTick() fires before any I/O events in the current iteration of the event loop. setImmediate() fires in the check phase, after I/O events. nextTick has higher priority but can starve the event loop if called recursively.
Q2: How do you handle uncaught exceptions in Node.js? Use process.on('uncaughtException') for synchronous code and process.on('unhandledRejection') for unhandled promise rejections. In production, these handlers should log the error and gracefully shut down the process (not attempt to continue).
Q3: What is the cluster module and when would you use it? cluster allows Node.js to create child processes (workers) that share the same server port. Used to utilise multi-core CPUs since Node is single-threaded. Each worker handles a subset of incoming connections.
Q4: What is the difference between require() and import in Node.js? require() is CommonJS (synchronous, loads at runtime). import is ES Modules (can be statically analysed, enables tree-shaking). Modern Node.js supports both, but they cannot be mixed in the same file.
Q5: How do you prevent memory leaks in a long-running Node.js server? Monitor heap size with process.memoryUsage(). Avoid storing large objects in global scope. Remove event listeners when no longer needed. Use WeakMap/WeakSet for caches. Profile with --inspect and Chrome DevTools.
Q6: What is middleware in Express.js? A function with signature (req, res, next) that intercepts the request-response cycle. Used for: authentication, logging, request parsing, error handling. Middleware is composable: app.use() chains them in order.
REST API design questions for Node.js interviews
Indian companies frequently test REST API design alongside Node.js questions:
- Idempotency: GET, PUT, DELETE should be idempotent. POST is not. Know how to implement idempotency keys for POST endpoints (to prevent duplicate payment submissions).
- Status codes: 200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorised, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable Entity, 429 Too Many Requests, 500 Internal Server Error. Know when to use each.
- Pagination: Offset-based (LIMIT/OFFSET in SQL) vs cursor-based (using the last record's ID). Cursor-based pagination is more efficient for large datasets and real-time feeds.
- Rate limiting: Implement with Redis (sliding window or token bucket). Express middleware like express-rate-limit provides a quick implementation.
- Input validation: Use Joi, Zod, or class-validator. Never trust client input. Validate at the request layer before hitting business logic.
- Error handling: Centralised error handling middleware in Express. Always return consistent error shapes: `{ error: { code: 'VALIDATION_ERROR', message: '...' } }`. Never leak stack traces to clients in production.
Practise Node.js technical and system design questions with HireStepX's AI mock interviewer. Get feedback on your explanations and close knowledge gaps before your interview.
Practice freePerformance optimisation questions
Senior Node.js positions test performance knowledge:
- Worker Threads: For CPU-intensive operations (image processing, complex calculations), use worker_threads to offload work from the main thread without blocking the event loop.
- Connection pooling: Database connections are expensive to create. Use a connection pool (pg-pool for PostgreSQL, mongoose connection pooling for MongoDB) to reuse connections.
- Caching strategies: Response caching with Redis. In-memory caching with node-cache for frequently-read, rarely-changed data. Avoid N+1 query problems by batching database lookups (DataLoader pattern).
- Compression: Use compression middleware in Express to gzip responses. Significant bandwidth savings for JSON APIs.
- PM2 and process management: Use PM2 in production for process management, clustering, log management, and zero-downtime reloads.
Frequently asked questions
Practice these questions on HireStepX