engineering · Fresher-friendly
Node.js Developer interview questions on async programming, Express.js, REST APIs, and database integration.
Explain the Node.js event loop. What are the phases in order?
Tip: Phases: timers, I/O callbacks, idle/prepare, poll, check (setImmediate), close callbacks. `process.nextTick` fires before ANY phase transition. Understanding this prevents subtle async ordering bugs.
What is the difference between `setTimeout`, `setImmediate`, and `process.nextTick`?
Tip: `process.nextTick` fires immediately after the current operation, before any I/O. `setImmediate` fires in the check phase — after I/O callbacks. `setTimeout(fn, 0)` fires in the timers phase. nextTick can starve I/O if used in a loop.
What are Node.js streams? Name the four types and a use case for each.
Tip: Readable (file read), Writable (file write), Duplex (TCP socket), Transform (gzip). Streams process data in chunks — ideal for large files, avoiding loading everything into memory. Pipe them: `fs.createReadStream().pipe(zlib.createGzip()).pipe(fs.createWriteStream())`.
How does clustering work in Node.js? Why use it?
Tip: Node.js is single-threaded and uses only one CPU core. Clustering forks the master process N times (one per CPU core) and load-balances connections across workers using the `cluster` module or PM2. PM2 is the practical production solution.
What is middleware in Express.js? Write a simple request-logging middleware.
Tip: Middleware is a function `(req, res, next) => {}` that has access to request/response and can modify them or pass control with `next()`. Example: `app.use((req, res, next) => { console.log(req.method, req.url); next(); })`.
How do you handle errors in async/await code in Node.js?
Tip: Use try/catch inside async functions. For Express routes, use async wrapper or `express-async-errors`. At the top level: attach `process.on("unhandledRejection", ...)`. Never swallow errors silently.
How do you secure an Express.js REST API?
Tip: Key measures: Helmet.js (security headers), rate limiting (express-rate-limit), input validation (Joi/Zod), parameterised queries, JWT auth with short expiry, CORS whitelist. HTTPS in production. Never log sensitive fields.
Describe a Node.js API you built. What was the architecture?
Tip: Cover: controller/service/repository layers, error handling strategy, middleware chain, auth approach, database choice, and one technical challenge you solved. "I built CRUD endpoints" is not enough — show architectural thinking.
A Node.js server starts dropping requests under high concurrency. What do you investigate?
Tip: Check: event loop lag (blocked by CPU-heavy sync code?), connection pool exhaustion, memory pressure causing GC pauses. Use clinic.js. Fix: offload CPU work to worker threads, add clustering, tune pool sizes.
What is the difference between CommonJS `require()` and ES module `import`?
Tip: CommonJS: synchronous, loads at runtime, dynamic. ES modules: asynchronous, static analysis allows tree-shaking, top-level `await` support. Node.js supports both — set `"type": "module"` in package.json for ESM.
What is `package.json` and what are its most important fields for a production service?
Tip: Key fields: `name`, `version`, `main`, `scripts` (start/build/test), `dependencies` vs `devDependencies`, `engines` (Node version), `type` (commonjs/module). Lock file is as important as `package.json` for reproducible builds.
Node.js vs Python (FastAPI/Flask) for a backend service — when would you choose each?
Tip: Node.js excels at real-time, high-concurrency I/O-bound services (WebSockets, streaming). Python/FastAPI excels when the team has ML/data science expertise or heavy numerical computation. Choose based on team skills and actual bottleneck, not hype.
Practice, not just reading
Upload your resume and practice a full Node.js Developer mock interview with AI-generated questions and rubric-based scoring across 5 dimensions — free to start.