1. What is NPM?
NPM (Node Package Manager) manages packages for Node.js. It provides an online registry for open-source modules and a CLI tool to install, update, or remove packages.
npm install express
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Node Js · Question Set
Node.js Fundamentals interview questions for placements and exams.
Questions
14
Included in this set
Subject
Node Js
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for Node Js.
NPM (Node Package Manager) manages packages for Node.js. It provides an online registry for open-source modules and a CLI tool to install, update, or remove packages.
npm install express
For complete preparation, combine this set with full subject-wise practice for Node Js. You can also explore other subjects and sets from the links below.
Node.js uses an event-driven, non-blocking I/O model. Incoming client requests go into an Event Queue, and the Event Loop processes them. Simple tasks run directly; complex or blocking tasks are handled by background threads in a thread pool. Once completed, results are sent back via callbacks or Promises.
Node.js uses a single thread to handle requests asynchronously. This approach prevents the overhead of managing multiple threads and allows it to scale efficiently with minimal memory usage through event-driven I/O operations.
A callback is a function passed as an argument to another function, executed once a task completes. It prevents blocking operations and allows asynchronous execution. However, deeply nested callbacks can lead to 'callback hell'.
fs.readFile('file.txt', (err, data) => { if (err) throw err; console.log(data.toString()); });Promises simplify asynchronous flow by chaining operations with `.then()` and handling errors with `.catch()`. They avoid nested callbacks, improve readability, and allow better error propagation.
I/O (Input/Output) refers to data transfer between a system and external resources like files, networks, or devices. Node.js optimizes I/O using non-blocking event-driven architecture to handle many concurrent operations efficiently.
Node.js is fast, lightweight, and highly scalable. It supports asynchronous non-blocking operations, making it perfect for real-time and I/O-heavy applications. It uses a single-threaded event loop model, reducing overhead and improving performance.
Node.js is used for real-time chat apps, streaming platforms, IoT systems, single-page applications, APIs, and microservices due to its scalability and event-driven nature.
Frontend (client-side) involves what users see and interact with—HTML, CSS, JavaScript, React, etc. Backend (server-side) handles data, APIs, and server logic using languages like Node.js, Python, or Java.
module.exports defines what values or functions a module exposes to other files. It allows encapsulation and reusability of code across different parts of an application.
// math.js
module.exports.add = (a,b)=>a+b;
// app.js
const math=require('./math');
console.log(math.add(2,3));Node.js is faster, supports asynchronous I/O, and allows using JavaScript both on frontend and backend. It’s lightweight, scalable, and ideal for data-intensive applications. In contrast, Java/PHP rely on multi-threaded blocking architectures.
Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome’s V8 engine. It allows running JavaScript on the server side instead of just in the browser. It is commonly used for building web servers, APIs, streaming applications, and real-time apps like chat or online games.
Node.js handles concurrency via its Event Loop and Worker Pool. The Event Loop continuously listens for new events, while the Worker Pool executes I/O or CPU-intensive operations in the background without blocking the main thread.
Modules are reusable JavaScript files that export specific functionality. Node.js includes built-in core modules like `fs`, `http`, `url`, and `stream`. Developers can also create custom modules using `module.exports`.
const fs = require('fs');
const data = fs.readFileSync('file.txt');