🚀 Node.js Interview Quiz (100 Questions with Answers)
1️⃣ Node.js Fundamentals (1–15)
1) What is Node.js?
Answer: A JavaScript runtime built on Chrome’s V8 engine.
Explanation: Node.js allows JS to run outside the browser, mainly for servers and tooling.
2) Is Node.js single-threaded?
Answer: Yes (but it uses background threads).
Explanation: JS runs on one thread, but Node offloads I/O to a thread pool.
3) What is V8?
Answer: Google’s JavaScript engine written in C++.
Explanation: Compiles JS to machine code for fast execution.
4) What is npm?
Answer: Node Package Manager.
Explanation: Manages third-party libraries and dependencies.
5) What is the purpose of package.json?
Answer: Metadata, scripts, dependencies, versioning.
Explanation: Central config file for Node projects.
6) What does node index.js do?
Answer: Executes the file in the Node runtime.
Explanation: Entry point for most Node applications.
7) What is process in Node.js?
Answer: A global object providing info about the current Node process.
Explanation: Used for env vars, exit codes, signals.
8) How do you access environment variables?
process.env.PORT
Explanation: Often used for config and secrets.
9) What is __dirname?
Answer: Absolute path of the current file’s directory.
Explanation: Useful for file system operations.
10) Difference between Node.js and browser JS?
Answer: Node has no DOM, but has filesystem, networking, OS access.
Explanation: Different runtimes, same language.
11) What is REPL?
Answer: Read–Eval–Print Loop.
Explanation: Interactive Node shell.
12) What is a Node module?
Answer: A reusable block of code.
Explanation: Encapsulated via CommonJS or ES Modules.
13) What file extension enables ES Modules in Node?
Answer: .mjs or “type”: “module”
Explanation: Enables import/export.
14) What does require() do?
Answer: Imports CommonJS modules.
Explanation: Synchronous loading.
15) What is npx?
Answer: Runs packages without installing globally.
Explanation: Useful for CLIs.
2️⃣ Event Loop & Async Internals (16–30)
16) What is the Node.js event loop?
Answer: Handles async operations and callback execution.
Explanation: Enables non-blocking I/O.
17) Is Node good for CPU-heavy tasks?
Answer: No.
Explanation: CPU work blocks the event loop.
18) What is non-blocking I/O?
Answer: Operations don’t stop JS execution.
Explanation: Core Node performance feature.
19) What is the libuv library?
Answer: C library handling async I/O.
Explanation: Manages event loop & thread pool.
20) What is the thread pool size?
Answer: Default = 4 threads.
Explanation: Configurable via UV_THREADPOOL_SIZE.
21) What goes into the thread pool?
Answer: fs, crypto, DNS, compression.
Explanation: CPU-like async tasks.
22) Order of execution?
setTimeout(()=>console.log(“A”));
Promise.resolve().then(()=>console.log(“B”));
Answer: B, then A
Explanation: Microtasks run before timers.
23) What is backpressure?
Answer: When data arrives faster than it’s processed.
Explanation: Streams handle this.
24) What are microtasks?
Answer: Promise callbacks.
Explanation: Executed before next event loop phase.
25) What is starvation?
Answer: Tasks never execute due to others dominating.
Explanation: Too many microtasks can delay timers.
26) How do you block the event loop?
Answer: Long loops, sync fs, CPU-heavy logic.
Explanation: Avoid at all costs.
27) What is setImmediate()?
Answer: Executes after I/O callbacks.
Explanation: Different timing than setTimeout(0).
28) What is process.nextTick()?
Answer: Executes before Promise microtasks.
Explanation: Can starve the event loop.
29) Should nextTick be used often?
Answer: No.
Explanation: Easy to misuse and block execution.
30) Why is Node fast?
Answer: Non-blocking async + V8 + event loop.
Explanation: Efficient I/O handling.
3️⃣ Modules, FS, Streams (31–45)
31) CommonJS vs ES Modules?
Answer: require vs import.
Explanation: ES Modules are standard.
32) Is require() synchronous?
Answer: Yes.
Explanation: Loaded at runtime.
33) What is fs.readFileSync() risk?
Answer: Blocks event loop.
Explanation: Avoid in servers.
34) Preferred file reading method?
Answer: fs.promises.readFile()
Explanation: Async and non-blocking.
35) What is a stream?
Answer: Data processed in chunks.
Explanation: Efficient memory usage.
36) Types of streams?
Answer: Readable, Writable, Duplex, Transform.
Explanation: Core Node concept.
37) Why use streams?
Answer: Handle large data efficiently.
Explanation: Avoid loading everything into memory.
38) What does .pipe() do?
Answer: Connects streams.
Explanation: Handles backpressure automatically.
39) What is a buffer?
Answer: Raw binary data.
Explanation: Used for file/network data.
40) Are buffers mutable?
Answer: Yes.
Explanation: Careful with shared buffers.
41) How do you check file existence safely?
Answer: fs.access()
Explanation: Avoid race conditions.
42) What is path traversal risk?
Answer: User accessing unintended files.
Explanation: Validate paths.
43) How do you delete a file async?
Answer: fs.unlink()
Explanation: Non-blocking.
44) What is process.cwd()?
Answer: Current working directory.
Explanation: Can differ from __dirname.
45) When to use streams over buffers?
Answer: Large files or continuous data.
Explanation: Better scalability.
4️⃣ Express & APIs (46–65)
46) What is Express.js?
Answer: Minimal Node web framework.
Explanation: Routing, middleware, HTTP handling.
47) What is middleware?
Answer: Functions executed in request lifecycle.
Explanation: Modify req/res or end cycle.
48) Order of middleware matters?
Answer: Yes.
Explanation: Executed top-down.
49) What is next()?
Answer: Moves to next middleware.
Explanation: Required to continue pipeline.
50) What is REST?
Answer: Architectural style for APIs.
Explanation: Stateless, resource-based.
51) Difference between PUT and PATCH?
Answer: PUT replaces; PATCH updates partially.
Explanation: Important REST distinction.
52) What is JSON middleware?
Answer: express.json()
Explanation: Parses request body.
53) How to handle errors in Express?
Answer: Error-handling middleware (err, req, res, next)
Explanation: Centralized error logic.
54) What is CORS?
Answer: Cross-Origin Resource Sharing.
Explanation: Browser security policy.
55) How do you enable CORS?
Answer: cors middleware.
Explanation: Server-controlled.
56) What is rate limiting?
Answer: Prevents abuse.
Explanation: Protects APIs.
57) What is HTTP status 401 vs 403?
Answer: 401 = unauthenticated; 403 = unauthorized.
Explanation: Common interview question.
58) What is JWT?
Answer: JSON Web Token.
Explanation: Stateless auth mechanism.
59) Where should JWT be stored?
Answer: HTTP-only cookies (preferred).
Explanation: Safer than localStorage.
60) What is CSRF?
Answer: Cross-Site Request Forgery.
Explanation: Mitigated with tokens.
61) What is input validation?
Answer: Ensuring correct data.
Explanation: Prevents injection attacks.
62) What is SQL injection risk?
Answer: Unsanitized queries.
Explanation: Use parameterized queries.
63) How do you structure large Express apps?
Answer: Routes, controllers, services, middleware.
Explanation: Separation of concerns.
64) What is MVC in Node?
Answer: Model–View–Controller.
Explanation: Common backend pattern.
65) Why avoid fat controllers?
Answer: Hard to test and maintain.
Explanation: Business logic belongs in services.
5️⃣ Performance, Security, Production (66–85)
66) What is clustering?
Answer: Using multiple Node processes.
Explanation: Utilizes multiple CPU cores.
67) What module supports clustering?
Answer: cluster
Explanation: Built-in.
68) What is PM2?
Answer: Process manager.
Explanation: Restarts crashes, clustering, logs.
69) How do you handle uncaught exceptions?
Answer: Log and restart process.
Explanation: App may be unstable.
70) What is memory leak in Node?
Answer: Objects not released.
Explanation: Leads to crashes.
71) How do you detect memory leaks?
Answer: Heap snapshots, profiling.
Explanation: Use Chrome DevTools.
72) What is graceful shutdown?
Answer: Finish requests before exit.
Explanation: Important in production.
73) How do you listen for shutdown signals?
Answer: process.on(“SIGTERM”)
Explanation: Clean up resources.
74) What is load balancing?
Answer: Distributing traffic.
Explanation: Improves reliability.
75) What is horizontal scaling?
Answer: More instances.
Explanation: Node-friendly.
76) Vertical scaling?
Answer: Bigger server.
Explanation: Limited growth.
77) What is logging best practice?
Answer: Structured logs (JSON).
Explanation: Easier monitoring.
78) What is dotenv?
Answer: Loads env vars from .env.
Explanation: Dev convenience.
79) Why not commit .env?
Answer: Security risk.
Explanation: Contains secrets.
80) What is helmet?
Answer: Security middleware.
Explanation: Sets safe HTTP headers.
81) What is HTTPS importance?
Answer: Encrypts traffic.
Explanation: Required for auth & security.
82) What is N+1 query problem?
Answer: Excessive DB queries.
Explanation: Performance killer.
83) How to optimize DB access?
Answer: Indexing, batching, caching.
Explanation: Backend fundamentals.
84) What is caching?
Answer: Store frequent results.
Explanation: Improves performance.
85) What tools monitor Node apps?
Answer: PM2, New Relic, Datadog.
Explanation: Production readiness.
6️⃣ Advanced & Architecture (86–100)
86) What is event-driven architecture?
Answer: Systems react to events.
Explanation: Node fits naturally.
87) What is message queue?
Answer: Async task processing.
Explanation: Redis, RabbitMQ, Kafka.
88) Why use workers?
Answer: Offload CPU work.
Explanation: Prevent event loop blocking.
89) What is worker_threads?
Answer: Multi-threaded JS execution.
Explanation: For CPU-heavy tasks.
90) Difference: workers vs cluster?
Answer: Workers share memory; cluster uses processes.
Explanation: Different trade-offs.
91) What is monolith vs microservices?
Answer: Single app vs distributed services.
Explanation: Architecture choice.
92) Node best use cases?
Answer: APIs, real-time apps, tooling.
Explanation: Not heavy computation.
93) What is WebSocket?
Answer: Persistent bi-directional connection.
Explanation: Real-time apps.
94) What is SSE?
Answer: Server-Sent Events.
Explanation: One-way streaming.
95) What is GraphQL vs REST?
Answer: Client-defined queries vs fixed endpoints.
Explanation: Different trade-offs.
96) What is middleware chaining risk?
Answer: Hard debugging.
Explanation: Keep middleware small.
97) What is API versioning?
Answer: Supporting multiple API versions.
Explanation: Avoid breaking clients.
98) What is idempotency?
Answer: Same request → same result.
Explanation: Important for retries.
99) What is a health check endpoint?
Answer: Status endpoint.
Explanation: Used by load balancers.
100) What makes a Node.js dev “senior”?
Answer: Understanding internals, async, performance, architecture.
Explanation: Not just syntax.