Node.js Interview Guide tailored for backend developers, ranging from beginner to advanced levels. This will help you prepare for interviews with clear structure, concepts, code snippets, and frequently asked questions.
🔰 1. Node.js Basics
✅ Topics:
- What is Node.js?
- Node.js architecture (Event Loop)
- Blocking vs Non-blocking I/O
- Global objects (
__dirname
,__filename
,require
, etc.) - npm vs npx
❓ Sample Questions:
- What is Node.js and why is it single-threaded?
- Explain the Event Loop with phases.
- Difference between
require
andimport
.
📦 2. Modules and File System
✅ Topics:
- CommonJS and ES Modules
- Built-in modules (
fs
,path
,http
, etc.) - Synchronous vs Asynchronous file operations
- Module caching
❓ Sample Questions:
- How does module caching work in Node.js?
- Explain the difference between
fs.readFile
andfs.readFileSync
.
📡 3. Asynchronous Programming
✅ Topics:
- Callbacks
- Promises
async/await
- Callback hell and how to avoid it
❓ Sample Questions:
- How does Node handle asynchronous code under the hood?
- Convert a callback-based function to Promise-based.
🌐 4. HTTP and Express.js
✅ Topics:
- Creating an HTTP server
- Express.js basics (middleware, routing, error handling)
- Request lifecycle
- REST API design patterns
❓ Sample Questions:
- How do you handle global error middleware in Express?
- Difference between middleware and route handler?
🗃️ 5. Database Integration
✅ Topics:
- MongoDB with Mongoose
- SQL with Sequelize / TypeORM
- Connecting to DBs asynchronously
- CRUD operations with async/await
❓ Sample Questions:
- How do you handle database connection failures?
- Compare ODM and ORM in Node.js.
🔐 6. Authentication & Authorization
✅ Topics:
- JWT tokens
- Passport.js
- Role-based access
- Session vs Token-based auth
❓ Sample Questions:
- How does JWT work and where is it stored?
- How would you protect admin routes in an Express app?
🛠️ 7. Best Practices & Clean Code
✅ Topics:
- Folder structure
- Error handling
- DTOs and validation (Joi, Zod)
- Environment variables (
dotenv
) - Logging (
winston
,morgan
)
❓ Sample Questions:
- How do you structure a large-scale Node.js project?
- What tools do you use for logging and monitoring?
🧪 8. Testing
✅ Topics:
- Unit testing with Jest / Mocha
- Supertest for API testing
- Mocks and spies
- Test structure and coverage
❓ Sample Questions:
- How do you test an Express middleware?
- What is the difference between unit and integration tests?
🧵 9. Performance & Advanced Topics
✅ Topics:
- Clustering and Worker Threads
- Memory leaks & Garbage collection
- Streams
- Rate limiting, throttling
- Redis caching
❓ Sample Questions:
- How would you scale a Node.js app?
- What is a stream in Node.js and how is it useful?
📦 10. DevOps & Production
✅ Topics:
- PM2 process manager
- Dockerizing a Node.js app
- CI/CD pipeline (basic overview)
- Environment config and secret handling
❓ Sample Questions:
- How do you handle Node app crashes in production?
- How would you use Docker for deploying a Node.js app?
📁 Bonus: Sample Project for Practice
Build a REST API for a To-Do App with:
- CRUD endpoints using Express
- MongoDB + Mongoose
- JWT Authentication
- Redis Caching
- Jest tests
- Dockerfile & PM2 setup