Top 50 Node.js Interview Questions Complete Summary and Quick Reference
A comprehensive summary of the top 50 Node.js interview questions event loop, modules, async programming, Express, MongoDB, security, performance, and deployment.
Top 50 Node.js Interview Questions Complete Summary
This is a complete quick-reference for the most common Node.js interview questions.
Event Loop (10 Questions)
- What is the event loop? Mechanism for non-blocking I/O in single-threaded Node.js
- What are the phases? Timers, Poll, Check, Close (microtasks between phases)
- setTimeout vs setImmediate vs nextTick? nextTick > Promise > setTimeout/setImmediate
- Why is Node.js single-threaded? Reduces context switching, uses libuv thread pool for I/O
- What is process.nextTick? Fires after current operation, before next phase (highest priority)
- What is the call stack? LIFO stack where V8 executes JavaScript functions
- What is the callback queue? FIFO queue of callbacks waiting to be executed
- What is libuv? C library that provides the event loop and thread pool
- What is the thread pool? 4 threads (default) for heavy I/O operations
- What is event loop starvation? nextTick or heavy sync code blocks the event loop
Modules (8 Questions)
- require vs import? CommonJS (sync) vs ES Modules (async)
- How does require work? Resolve, Load, Wrap, Evaluate, Cache
- What is module caching? Same instance returned on repeated requires
- Circular dependencies? Returns partial exports; avoid by refactoring
- module.exports vs exports? Always use module.exports
- What are core modules? http, fs, path, crypto, events, stream
- What is __dirname? Absolute path of the current module's directory
- What is package.json? Project manifest with dependencies and scripts
Async Programming (8 Questions)
- What is a callback? Function executed after an async operation
- What is callback hell? Deeply nested callbacks; fix with Promises/async-await
- What is a Promise? Object representing a future value (pending/fulfilled/rejected)
- What is async/await? Syntactic sugar over Promises (synchronous-looking async code)
- Promise.all vs allSettled vs race? All (fail-fast), allSettled (all results), race (first)
- How to handle async errors? try-catch with async/await
- How to run parallel? Promise.all([fetchA(), fetchB(), fetchC()])
- How to limit concurrency? Batch processing with Promise.all per batch
Express (7 Questions)
- What is middleware? Function in request-response cycle with next()
- app.use vs app.get? All methods vs specific method
- Types of middleware? Application, Router, Built-in, Error-handling, Third-party
- Error handling in Express? 4-param middleware (err, req, res, next)
- What is asyncHandler? Wrapper that catches async errors and passes to next()
- What is Express Router? Modular route organization
- What is req.body? Parsed request body (requires express.json() middleware)
MongoDB/Mongoose (7 Questions)
- MongoDB vs Mongoose? Database vs ODM with schemas and validation
- Schema vs Model? Structure definition vs constructor for documents
- What are indexes? Sorted structures that speed up queries
- What is ref and populate? Reference + replace ObjectId with document
- What is aggregation? Pipeline of stages ($match, $group, $sort, $lookup)
- find vs findOne? Array vs single document
- What are hooks? pre/post middleware (hash password in pre-save)
Security (5 Questions)
- How to implement auth? JWT in HTTP-only cookies + auth middleware
- What is NoSQL injection? Malicious operators in queries; prevent with express-mongo-sanitize
- How to store passwords? bcrypt with salt and cost factor
- What security headers? HSTS, X-Frame-Options, X-Content-Type-Options, CSP (use helmet)
- How to rate limit? express-rate-limit middleware
Performance (5 Questions)
- How to scale? Cluster mode, load balancing, caching, CDN
- What are streams? Process data in chunks (memory-efficient for large data)
- How to handle CPU-intensive tasks? worker_threads, child_process, or queues
- How to detect memory leaks? Monitor process.memoryUsage() periodically
- How to optimize queries? Indexes, projection, lean(), pagination, caching
The Takeaway
These 50 questions cover the most important Node.js interview topics: event loop (phases, microtasks, single-thread), modules (require/import, caching, circular deps), async programming (callbacks, Promises, async/await, Promise.all), Express (middleware, error handling, Router), MongoDB/Mongoose (schemas, indexes, populate, aggregation), security (JWT, bcrypt, injection, headers, rate limiting), and performance (clustering, streams, worker threads, memory, query optimization). Master these to ace any Node.js interview.
Event loop (phases, microtasks, single-thread), modules (require/import, caching, circular deps), async programming (callbacks, Promises, async/await), Express (middleware, error handling, Router), MongoDB/Mongoose (schemas, indexes, populate, aggregation), security (JWT, bcrypt, injection, headers), and performance (clustering, streams, worker threads, memory, query optimization).
The event loop how it works, its phases (timers, poll, check, close), the difference between setTimeout/setImmediate/process.nextTick, and why Node.js is single-threaded. Understanding the event loop is essential for any Node.js developer.
Study the event loop (phases, microtasks vs macrotasks), async programming (Promises, async/await, Promise.all), Express (middleware, error handling), MongoDB (indexes, populate, aggregation), security (JWT, bcrypt, NoSQL injection), performance (clustering, streams, worker threads), and deployment (PM2, Nginx, Docker, CI/CD). Practice coding questions.
Execution order: process.nextTick (after current operation, before next phase), Promise.then (microtask, after nextTick), setTimeout (timers phase), setImmediate (check phase, after I/O). nextTick and Promise are microtasks that run between phases; setTimeout and setImmediate are macrotasks that run in specific phases.
Use JWT in HTTP-only cookies (not localStorage), bcrypt for passwords (with salt and cost factor), express-mongo-sanitize for NoSQL injection prevention, helmet for security headers, express-rate-limit for rate limiting, input validation, CORS with specific origins, and HTTPS with Let's Encrypt. Never hardcode secrets use environment variables.
Ready to master Node.js completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master Node.js
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

