NodeJs Interviews – Top Questions & Answers for Web Developers
Node.js is a runtime environment that lets JavaScript run outside the browser using the V8 engine. It’s designed for building fast, scalable network applications.
Node.js uses a single-threaded model to avoid context switching overhead and simplify asynchronous programming. Heavy work is offloaded to the internal thread-pool.
V8 is Google’s high-performance JavaScript engine that compiles JS directly into machine code, making Node.js extremely fast.
The Event Loop is the heart of Node.js. It handles callbacks, async tasks, timers, I/O operations, and keeps the app non-blocking.
Non-blocking I/O allows Node.js to handle multiple operations simultaneously without waiting for slow tasks like database or file operations.
npm is the default package manager for Node.js used to install, update, publish, and manage dependencies.
Modules are reusable blocks of code. Node.js supports CommonJS (require) and ES Modules (import) depending on project settings.
| CommonJS | ES Modules |
|---|---|
| require() | import |
| Synchronous | Asynchronous |
| Used mostly in Node.js | Browser + Node.js |
A metadata file that stores project config, dependencies, scripts, version, entry point, and more.
It locks the exact dependency versions to ensure consistent installs across systems.
Packages used only during development, like testing or bundling tools.
Express.js is a lightweight Node.js framework used to build REST APIs and server-side applications.
Middleware functions run between the request and response cycle for tasks like logging, validation, error handling, etc.
const http = require("http");
http.createServer((req, res) => {
res.end("Hello Node!");
}).listen(3000);A way to execute tasks without blocking other operations using callbacks, promises, or async/await.
Promises represent future values and help handle async operations in a cleaner way than callbacks.
Syntactic sugar over Promises that makes async code look synchronous.
A messy nested callback structure that makes code unreadable.
Use:
- Promises
- async/await
- Named functions
- Modular code
A core module that allows you to create and listen to custom events.
const EventEmitter = require("events");
const emitter = new EventEmitter();
emitter.on("greet", () => console.log("Hello"));
emitter.emit("greet");The fs (File System) module handles file operations like read, write, update, and delete.
- readFile — async, non-blocking
- readFileSync — sync, blocks the thread
A built-in Node module used to create web servers.
Clustering allows Node.js to use multiple CPU cores by creating worker processes that share the same server port.
Distributing incoming network traffic across multiple servers or processes.
A microtask that executes before the next event loop iteration.
Tiny tasks queued for immediate execution (Promises, nextTick).
A temporary memory storage used to handle binary data like files, streams, or network packets.
Streams are data-handling methods that let you process chunks of data piece-by-piece.
- Readable
- Writable
- Duplex
- Transform
Used to pass output from one stream to another.
A browser security feature that restricts cross-origin requests.
const cors = require("cors");
app.use(cors());Multiple middleware execute sequentially until the response is sent.
Helmet adds HTTP security headers to protect Express apps.
A method to limit the number of requests from a client to avoid DDoS attacks.
JSON Web Tokens are used for secure authentication between client and server.
Client gets a signed token → attaches it to headers → server verifies → grants access.
A library to load environment variables from a .env file.
A dev tool that automatically restarts your Node.js server on file changes.
A production process manager for Node.js to keep applications alive, load balanced, and monitored.
REST is an architectural style using HTTP methods to create scalable APIs.
A high-performance RPC framework using Protocol Buffers instead of JSON.
A library used for real-time communication (chat apps, live updates).
Small data pieces stored in the browser for sessions or preferences.
A server-side stored user state.
| Session | JWT |
|---|---|
| Stored server-side | Stored client-side |
| Heavy for scaling | Lightweight |
| Works well for web apps | Great for APIs |
A hashing library used to safely store passwords.
A NoSQL database often used with Node.js for flexible, JSON-like data storage.
An ODM library that simplifies CRUD operations in MongoDB.
SQL uses tables; NoSQL uses documents, key-value, or graphs.
- PUT → replace entire record
- PATCH → update specific fields
app.use((err, req, res, next) => {
res.status(500).send(err.message);
});Automatically reloads modules without restarting the server during development.
Node's built-in module for hashing, encryption, and secure random generation.
Allows executing external applications or shell commands from Node.
Converts callback-based functions into Promises.
Creates new worker processes.
Provides system information like CPU, RAM, OS type.
Prevents a function from running too frequently.
Delays function execution until the last event fires.
Storing data temporarily to reduce load and increase speed.
Redis is used as an in-memory data store for caching sessions or frequently-used data.
Environment variables accessible inside Node.
The sequence middleware is defined matters; earlier ones run first.
A centralized entry point for all microservices.
A system architecture where each feature is a separate small service.
A single, large application with tightly-coupled modules.
A popular library for rate-limiting in Express.
Cross-Site Request Forgery — an attack tricking users into unwanted actions.
Use CSRF tokens, SameSite cookies, and proper validation.
Cross-Site Scripting — injecting JS into web pages.
Input sanitization and using Helmet.
Helps work with file and directory paths.
Provides operating system-level information.
A state where two tasks wait for each other forever.
Yes, through Worker Threads (introduced in Node 10.5).
Used for CPU-intensive tasks like crypto or image processing.
forEach cannot use async/await properly; for...of can.
Catching exceptions and preventing app crashes.
Terminates a process programmatically.
Equivalent to window in browsers, but called global.
Read-Eval-Print-Loop: Node’s interactive shell.
Unused memory not released, causing increased RAM usage.
Use profiling tools, avoid global variables, and manage listeners properly.
Node supports native ES modules using "type": "module" in package.json.
Identifies the type of content being served (e.g., text/html).
Compresses responses to reduce bandwidth usage.
Closing server connections safely before stopping the server.
A popular logging library for Node.js.
HTTP request logger middleware.
Keeping multiple API versions active using routes like /v1, /v2.
Handles unmatched routes.
Server-Side Rendering — rendering pages on the server.
Server determines the best content format based on client headers.
A caching header that helps the client validate resources.
Using cache across multiple processes or servers.
Tools like Webpack, Babel, or ESBuild to bundle and optimize code.
- Fast
- Scalable
- Huge ecosystem
- Perfect for real-time apps
- Uses JavaScript end-to-end