Node.js powers the backend of most Indian startup APIs. Swiggy, Razorpay, CRED, Meesho, and hundreds of funded Indian startups use Node.js for their primary backend services. This guide covers the complete Node.js developer interview preparation path for India 2026: event loop, async patterns, Express.js, and production architecture.
Node.js event loop and async programming interview questions
Node.js event loop interview questions:
1. 'How does the Node.js event loop work?' Node.js is single-threaded but non-blocking, thanks to the event loop. The event loop has 6 phases that run in a fixed order: timers (setTimeout, setInterval callbacks), pending callbacks (I/O callbacks deferred to next iteration), idle/prepare (internal), poll (retrieve new I/O events; execute I/O callbacks), check (setImmediate callbacks), and close callbacks. Between each phase, Node.js drains the microtask queue (Promises + process.nextTick) and the nextTick queue. process.nextTick runs before Promises; both run before the next event loop phase.
2. 'What is the difference between process.nextTick, setImmediate, and setTimeout?' process.nextTick: queued in the nextTick queue; runs before any I/O events and before Promise microtasks in the same iteration. setImmediate: runs in the check phase of the event loop (after I/O callbacks). setTimeout(fn, 0): runs in the timers phase of the next loop iteration; may run before or after setImmediate depending on the context (the ordering is not guaranteed when called from the main module; from within an I/O cycle, setImmediate always runs before setTimeout).
3. 'What is callback hell and how is it solved?' Callback hell: deeply nested callbacks that make code hard to read and maintain. Solutions in order of modernity: Promises (then/catch chaining), async/await (syntactic sugar over Promises; makes async code look synchronous), and modularisation (extract callback logic into named functions). Node.js 18+ supports top-level await.
4. 'What is the cluster module and why is it used?' Node.js is single-threaded, so it uses only one CPU core by default. The cluster module allows a master process to fork multiple worker processes, each on a different CPU core. Each worker shares the same port (the master distributes incoming connections). Use the cluster module or PM2 (which does clustering automatically with pm2 start app.js -i max) to utilise all CPU cores on a production server.
5. 'What are streams in Node.js?' Streams process data in chunks instead of loading the entire dataset into memory. Types: Readable (fs.createReadStream), Writable (fs.createWriteStream), Duplex (TCP socket), Transform (zlib, crypto). Use streams for: reading large files, processing large HTTP request/response bodies, piping data from one source to another. A pipe() connects a readable stream to a writable stream: fs.createReadStream('input.csv').pipe(processStream).pipe(fs.createWriteStream('output.json')).
Express.js and production architecture interview questions
Express.js and REST API design questions:
1. 'What is middleware in Express.js?' Middleware is a function with access to req, res, and next. Middleware runs in order, can modify req and res, and must call next() to pass control to the next middleware (or end the request-response cycle). Types: application-level (app.use()), router-level, error-handling (4 parameters: err, req, res, next), built-in (express.json(), express.static()), and third-party (cors, morgan, helmet).
2. 'How do you handle errors in Express.js?' Error handling middleware has 4 parameters (err, req, res, next). Place it AFTER all routes and regular middleware. Throw errors in async route handlers by wrapping in try/catch and calling next(err), or use an async middleware wrapper (express-async-errors or a custom asyncHandler). Always send a consistent error response: { ok: false, error: { code, message, requestId } }.
3. 'What is CORS and how do you configure it in Node.js?' CORS (Cross-Origin Resource Sharing): a browser security mechanism that blocks cross-origin requests by default. Server must respond with appropriate Access-Control-Allow-Origin headers. In Express: use the cors npm package. For production: cors({ origin: ['https://yourapp.com', 'https://staging.yourapp.com'] }). Never use cors({ origin: '*' }) in production for authenticated APIs.
Node.js production architecture:
4. 'How do you scale a Node.js application in production?' Horizontal scaling: multiple Node.js instances behind a load balancer (AWS ALB, Nginx). Each instance uses PM2 cluster mode for CPU utilisation. Shared state (sessions, cache) must live in Redis (not in-process memory). Database connection pooling: each process maintains its own pool; configure max pool size to avoid overwhelming the database. Worker threads: for CPU-intensive tasks (image processing, PDF generation), use Node.js worker_threads to offload from the event loop. Message queues: for long-running tasks (sending 10,000 emails), use a queue (Bull/BullMQ with Redis, AWS SQS) and process them in separate worker processes.
5. 'What is rate limiting and how is it implemented in Node.js?' Rate limiting prevents API abuse. Implementation: express-rate-limit for simple per-IP limiting; for per-user limits, track in Redis (increment a counter per user per time window using Redis INCR + EXPIRE). Sliding window vs fixed window: fixed window can allow 2x the rate at window boundaries; sliding window is more accurate but slightly more complex. At most Indian startups, express-rate-limit + Redis is the standard implementation.
Frequently asked questions
Explore more