🎯 Master Your Career

Interview-Bytes

Expertly curated technical interview questions,
simplified into manageable lessons.

Showing 1–10 of 22 questions

1

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.

2

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

3

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.

4

❓ 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.

Code Instance
console.log("start"); 
setTimeout(() => console.log("Timeout"), 1000); 
console.log("end");
5

📦 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.

6

🚀 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.

7

❓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

8

🔔 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!

Code Instance
const EventEmitter = require('events');
const eventEmitter = new EventEmitter();

// Register an event listener
eventEmitter.on('greet', () => {
  console.log('Hello, world!');
});

// Emit the event
eventEmitter.emit('greet');
9

📂 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.

Code Instance
const fs = require('fs');

app.get('/file', (req, res) => {
  fs.readFile('file.txt', 'utf8', (err, data) => {
    if (err) res.status(500).send('Error reading file');
    res.send(data);
  });
});
10

💡 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.

Code Instance
const fs = require('fs');

const readStream = fs.createReadStream('largefile.txt');

readStream.on('data', (chunk) => {
  console.log(`Received ${chunk.length} bytes of data.`);
});

readStream.on('end', () => {
  console.log('Finished reading the file.');
});