Interview Bytes
Tackling the topics we work with daily, yet often struggle to summarize. Interview Bytes delivers concise, practical answers to the questions that matter, helping you stay sharp and interview-ready.
What do you mean by "Node.js is a JavaScript runtime"?
- Historically, JavaScript only ran in browsers and was limited to DOM manipulation and event handling.
- Node.js allows JavaScript to run outside the browser using chrome’s V8 engine
- It provides an environment where JS can interact with the system, making it usable for backend development.
- It allows JavaScript to handle backend tasks that were traditionally handled by languages like Java or Python.
Role of Javascript in development of web ?
- In early 90s there were only static pages on web.
- Then for client side scripting ( dynamic frontend ), javascript was introduced.
- This led to development of JS engines like SpiderMonkey, V8 etc
- These engines allows browsers to execute javascript code.
- Early adopters of Javascript’s features were eBay, Yahoo, Amazon etc
- Different engines may support different versions of ECMAScript
Is V8 just a JavaScript compiler? How do they compare to C and Java?
Its a complete runtime environment. It compiles frequently used code for speed, interpret the rest, and manage memory automatically, handling JS's dynamic nature efficiently.
While C is compiled ahead-of-time into machine code. Java is compiled to bytecode, then JVM uses JIT to compile that to machine code. In V8, JS is directly JIT compiled to machine code at runtime instead of any intermediary code.
❓ What is the Node.js event loop?
- Node.js uses an event loop to manage asynchronous tasks while staying single-threaded.
- It handles tasks like file I/O & API calls outside the main thread, running callbacks only when the main thread is free.
Example -
Sync tasks(start,end) run first => Async task(Timeout) placed in Queue => After 1 sec event loop checks & executes callback.
console.log("start"); setTimeout(() => console.log("Timeout"), 1000); console.log("end");
📦 What is package.json in Node.js?
File that manager our project, It is automatically created when we do npm init. It has -
- Project Metadata: Contains name, version, description.
- Dependency Management: Lists required packages.
- Script Commands: Defines npm scripts for automation (e.g., start, test).
- Version Control: Ensures consistent package versions across environments.
- Configuration: Stores settings for tools & libraries.
🚀 What is npm in Node.js?
A package manager/ tool to manage dependencies, scripts and libraries in Node.js project. It allows to include 3rd party code. It is comparable to pip in python and maven in java.
❓What is a Module System in Node.js?
Module is reusable code. A module system is used to organize code in seperate functionalities.
Types of Module System -
1️⃣ CommonJs- Default Module system in nodejs. It uses require() to import and module.exports. Synchronously loaded.
2️⃣ Ecmascript Modules(ESM)- New standard introduced in ES6. It uses import and export syntax and is asynchronously loaded.
Note - ESM is now supported in nodejs with .mjs extension or enabling in package.json
🔔 What is EventEmitter in Node.js?
It is part of the core events module, enabling objects to communicate via events (async)
It is used in many core modules like (http, fs etc).
It can be used for event-driven architecture!

📂 How Node.js handles file operations?
It uses the fs module for working with the file system.
Use case - When a user requests a file (e.g., an image or document), Node.js reads the file asynchronously, allowing the server to handle other requests.
Asynchronous I/O prevents blocking other requests!
There is another method readFileSync which reads file synchronously.

💡 What are Streams in Node.js?
Streams handle I/O efficiently by processing data in chunks instead of loading it all at once. Ideal for large files or real-time data. Types of Stream -
1. Readable: For reading data
2. Writable: For writing data
3. Duplex: Both read & write
4. Transform: Modify data while reading/writing
It is perfect for video streaming, file handling, or large datasets! Below is example of using Streams for File Handling.

💡 What are Callbacks in Node.js?
Callbacks are functions passed as argument to another function and gets executed after the main func has completed its task. In node.js they are crucial for non-blocking behaviour, callbacks are passed to handle async tasks.
How it works ? The async task starts → Node.js keeps working → When done, the event loop triggers the callback to handle the result.

💡What are process.nextTick() & setImmediate() in Node.js?
1️⃣ process.nextTick() - Executes before the next event loop. Great for immediate logic after a task, like error handling or cleanup.
2️⃣ setImmediate() - Executes after I/O events in the event loop. Useful for deferred tasks that shouldn’t block the current cycle.
.jpg)
.jpg)
🔍 What is Encoding?
1️⃣ Text Encoding: (UTF-8, ASCII) Converts characters into bytes so computers can store and display text.
2️⃣ Binary: Raw 0s & 1s, the language of computers.
3️⃣ Base64: Converts binary data( images, files) to text for safe web/email transmission.
4️⃣ URL Encoding: Handles special characters in URLs (%20 for spaces).
5️⃣ Hex: Easier-to-read format for binary (0-9, A-F).
💡 What is the Buffer class in Node.js?
It is a global object which handles raw binary data in memory (Space is allocated in RAM) allowing us to manipulate raw data streams efficiently
It is great for file I/O and Network communications
Example - Reading a binary file using buffer. fs.readFile reads binary data from file & saves in buffer. Buffer.toString(‘base64’) is used to convert raw binary data to base64

🚀 What is Express.js and why is it required?
Its a minimal, flexible web framework for Node.js. It simplifies tasks like routing, handling requests/responses, and managing middleware.
It -> Reduces boilerplate code, Makes server-side dev fast & clean, Supports middleware, Simplifies Routing, Handles HTTP Methods, Serves Static Files, Supports Templating Engines and has Good Error Handling
Alternatives to Express - Koa.js, Fastify.js ( flexible & modern) , Hapi.js ( More config )

🙋 What is middleware in Express.js?
It is a function that executes during request-response cycle in express
Can use built-in, 3rd party or custom middlewares.
Used for tasks like logging, authentication, and parsing data.

🧭 What is routing in Express.js?
It defines how an app responds to client requests at specific URL paths and HTTP methods (GET, POST, etc.). Its how you handle different actions (e.g. displaying data, creating resources) based on the URL.
How routing works in Express -
- Express supports all HTTP methods.
- Dynamic routes with parameters (e.g., /user/:id).
- Multiple handlers per route!

🧭 What are route parameters in Express.js?
Route parameters allow you to capture values from the URL. They are placeholders in the route definition (e.g., /user/:id).
Useful when u want to create dynamic routes that respond differently based on values in URL.
How route parameters work:
- Parameters are prefixed with : in the route path.
- You can access them using req.params inside your route handler.

❓What are query parameters in Express.js?
Query parameters are part of the URL that come after the question mark (?) and are used to send data as key-value pairs.
Can be accessed using req.query.
Example - /search?name=phone&category=electronics

📋 Difference between res.send(), res.json(), and res.end() in Express.js?
- res.send(): It sends various types. Automatically detects and sets Content-Type header. It auto-ends response.
- res.json(): Sends JSON response with correct headers. It also sets Content-Type to application/json.
res.end(): Ends response without sending data (unless specified).
☠️ Handling errors in Express.js ?
- Define error-handling middleware with 4 args: (err, req, res, next)
- Use next(err) to pass errors to the handler.
- For async errors, use try/catch and pass errors to next().

📁How to serve static files in Express.js ?
- Use express.static('folder') to serve HTML, CSS, images, etc.
- For multiple directories, use express.static() multiple times.
- Can also add a virtual path prefix for custom routes.
