Backend JavaScript Interview Questions (Node.js)
This article covers backend-focused JavaScript and Node.js interview questions, from fundamentals to advanced system design. Each section includes conceptual questions, scenario-based questions, and practical coding prompts.
1. Core JavaScript (Backend-Relevant)
Even backend interviews expect strong JS fundamentals.
Key Topics
- Closures
- Scopes & hoisting
thisbinding- Prototypes & classes
- Async patterns: callbacks, promises, async/await
- Event loop (browser vs Node differences)
Sample Questions
- Explain how closures work. Why are they useful in backend code?
- What is the difference between microtasks and macrotasks in Node.js?
- Why does
async/awaitstill use promises under the hood? - What is the difference between
process.nextTick()andqueueMicrotask()? - Does Node use the browser event loop? What’s the difference?
2. Event Loop & Asynchronous Behavior
Backend roles require deeper knowledge of Node's internals.
Sample Questions
- Walk me through the 6 phases of the Node.js event loop.
- What is libuv? What problems does it solve?
- What happens when you call
setTimeout(fn, 0)? - When does Node execute microtasks?
- Compare
setImmediatevssetTimeout. - How do promises integrate with the event loop in Node.js?
Scenario
A heavy CPU task blocks your server. How do you fix this?
- Worker threads
- Offloading to another service
- Breaking work into chunks (
setImmediate)
3. Node APIs & Runtime Behavior
Sample Questions
- How do streams work internally?
- What is backpressure? How does Node handle it?
- Explain different kinds of streams: readable, writable, duplex, transform.
- What is the difference between
fs.readFileandfs.createReadStream? - When would you use
Buffer.allocUnsafe()? - What is the role of the threadpool in Node?
4. Architecture & Scaling
Sample Questions
- Why is Node.js good for I/O-bound tasks but not CPU-heavy tasks?
- What are worker threads? When should you use them?
- What is clustering in Node.js? What does it NOT solve?
- How do you scale a Node application horizontally?
- What is PM2 and why is it used in production?
- How would you design a rate limiter in Node?
5. Networking & HTTP
Sample Questions
- Explain the lifecycle of an HTTP request in Node.
- What is
Keep-Alive? How does it impact performance? - How do you handle slowloris attacks in Node.js?
- What is chunked transfer encoding?
- Explain the difference between HTTP/1.1, HTTP/2, and HTTP/3.
- What is a reverse proxy? Why do we use Nginx with Node?
6. Databases & Persistence
Sample Questions
- How do you optimize database connections in Node?
- What are connection pools and why do we need them?
- How does Node handle long-running queries?
- Why should database calls NOT block the event loop?
7. Security
Sample Questions
- What is SQL injection and how do you prevent it in Node?
- What is CSRF? Is it relevant on backend-only APIs?
- What is CORS and how does Node handle it?
- How do you securely manage secrets in Node.js?
- What is prototype pollution? How do you mitigate it?
8. Error Handling & Reliability
Sample Questions
- Why is
throwinside an async function dangerous? - How do you handle uncaught exceptions?
- How do you ensure graceful shutdown of a Node server?
- What happens if a promise rejection is unhandled?
- How do you build retry logic for failed I/O operations?
9. Performance, Monitoring & Debugging
Sample Questions
- How do you detect memory leaks in Node?
- What tools are available for performance profiling?
- What is a flamegraph?
- How does garbage collection work in V8?
- How do you implement caching in Node.js?
10. System Design (Backend JS)
Sample Questions
- Design a real-time chat server using Node.
- Design a high-throughput file upload pipeline.
- Build a distributed job queue.
- How would you design a scalable notification system?
- Build a streaming-based log processing system.
11. Coding Problems (Backend-Oriented)
- Implement a streaming CSV parser.
- Implement a rate limiter (token bucket / sliding window).
- Build a basic in-memory message queue.
- Implement a function to retry a promise with exponential backoff.
- Write a Node server that can handle 100k concurrent connections.
12. Bonus: Practical Take-home Assignments
- Build a file upload service with streaming + chunking + retry.
- Build a local cache with TTL and LRU.
- Implement a pub/sub event system.
- Build a Node CLI tool.