NodeJS Interview Questions & Answers
Complete NodeJS interview preparation guide.
NodeJS Interview Roadmap
Junior
- Modules
- NPM
- File System
- Events
- Buffers
Mid-Level
- Event Loop
- Streams
- Cluster
- Worker Threads
- Authentication
Senior
- Performance
- Scaling
- Microservices
- Caching
- Security
What is NodeJS?
NodeJS is a JavaScript runtime built on Google's V8 Engine that allows JavaScript to run outside the browser.
Key Characteristics
- Single-threaded
- Event-driven
- Non-blocking I/O
- Asynchronous programming model
Common Use Cases
- REST APIs
- Real-time applications
- Microservices
- Streaming services
- Chat applications
Explain the Event Loop in NodeJS
The Event Loop allows NodeJS to perform non-blocking operations even though JavaScript runs on a single thread.
Execution Flow
- Call Stack
- Node APIs / Libuv
- Callback Queue
- Event Loop
Example
console.log('Start');
setTimeout(() => {
console.log('Timer');
}, 0);
console.log('End');Output
Start
End
TimerExpected Answer: The callback enters the Callback Queue and waits until the Call Stack becomes empty.
Predict the Output
console.log('A');
setTimeout(() => console.log('B'));
Promise.resolve()
.then(() => console.log('C'));
console.log('D');Correct Output
A
D
C
BExplanation
- Promise callbacks enter Microtask Queue
- Microtasks execute before Callback Queue
- setTimeout callback executes last
Streams vs Buffers
Both are used for handling data, but work differently.
Streams
fs.createReadStream('large-file.txt');- Processes data in chunks
- Low memory usage
- Ideal for large files
Buffers
fs.readFile('large-file.txt');- Loads entire file into memory
- Simpler API
- Not ideal for huge files
What are Worker Threads?
Worker Threads allow CPU-intensive tasks to run on separate threads, preventing the Event Loop from being blocked.
const { Worker } = require('worker_threads');
const worker = new Worker('./worker.js');Common Use Cases
- Image processing
- PDF generation
- Data analysis
- Encryption
Expected Answer: For I/O operations because NodeJS already handles them asynchronously.
Implement a Simple Rate Limiter
Restrict a user to a fixed number of requests.
const requests = {};
function allowRequest(ip) {
requests[ip] ??= 0;
if (requests[ip] >= 5) {
return false;
}
requests[ip]++;
return true;
}Interview Discussion Points
- Memory usage
- Distributed systems
- Redis implementation
- Sliding window algorithm
How Would You Scale NodeJS to 10 Million Users?
Expected Topics
- Load Balancer
- Horizontal Scaling
- Microservices
- Redis Cache
- Database Sharding
- CDN
- Message Queues
- Monitoring
Strong Candidate: Discusses architecture, bottlenecks, caching strategy and distributed systems.
Frequently Asked Questions
Is Node.js still relevant in 2026?
Yes. Node.js remains one of the most popular backend technologies for APIs, microservices and real-time applications.
Do companies ask event loop questions?
Yes. Event Loop, Streams, Async Programming and Performance are very common Node.js interview topics.
Are coding questions included?
Yes. Practical coding and debugging scenarios are included.
