Node Js Notes
Node Js Notes
MODULE 1
[Link] Basics
Understand what [Link] is, how it runs JavaScript outside the browser, and how code is
organized into modules.
[Link] 1/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. What is [Link]
REAL-WORLD EXAMPLE
USE CASE
Building REST APIs, real-time chat servers, payment backends, admin dashboards, CLI tools,
and automation scripts.
ADVANTAGES
COMMON MISTAKES
Calling [Link] a programming language. JavaScript is the language; [Link] is the runtime.
Using [Link] for heavy CPU work without workers or a separate service.
Ignoring async behavior and expecting code to always run top-to-bottom.
INTERVIEW QUESTIONS WITH ANSWERS
Q. Is [Link] a framework?
A. No. [Link] is a runtime environment. [Link] is a framework built on top of [Link].
Q. Why is [Link] popular?
A. It is fast for I/O operations, uses JavaScript, has npm, and is excellent for API development.
PRACTICE AND CODING TASKS
[Link] 2/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] does not wait for slow tasks like file [Link] uses an event-driven, non-blocking I/O
reading, database calls, or API calls. Hinglish: model. The event loop coordinates
Agar ek kaam time le raha hai, Node rukta asynchronous tasks and executes callbacks
nahi; dusra kaam process kar leta hai. when operations complete.
REAL-WORLD EXAMPLE
setTimeout(() => {
[Link]("3. Pizza ready");
}, 2000);
USE CASE
Handling many users at the same time, such as API requests, database calls, file uploads, and
chat messages.
ADVANTAGES
Blocking the event loop with heavy loops or synchronous CPU work.
Thinking setTimeout runs exactly after the given time; it runs after the event loop is free.
Not understanding why async output order is different.
INTERVIEW QUESTIONS WITH ANSWERS
Write code that prints A, then schedules B after 2 seconds, then prints C.
Explain why output becomes A, C, B.
Try replacing setTimeout with a file read later in Module 2.
[Link] 3/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. Installing [Link]
Installing [Link] gives your computer the [Link] installation provides the node runtime
ability to run JavaScript files directly. Hinglish: and npm package manager, enabling server-
Browser ke bina JS chalane ke liye Node install side JavaScript execution and dependency
karna padta hai. management.
REAL-WORLD EXAMPLE
node -v
npm -v
# Run a file
node [Link]
USE CASE
Required for backend development, Express apps, npm packages, testing tools, and deployment
workflows.
ADVANTAGES
COMMON MISTAKES
Q. What is npm?
A. npm is the package manager used to install and manage JavaScript libraries.
[Link] 4/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
A [Link] program is usually a .js file run by [Link] applications are executed using the
the node command. Hinglish: [Link] file banao, node runtime. The runtime loads the file,
usme code likho, phir terminal me node [Link] executes JavaScript, and provides access to
chalao. Node-specific APIs.
REAL-WORLD EXAMPLE
// [Link]
const http = require("node:http");
[Link](3000, () => {
[Link]("Server running on [Link]
});
USE CASE
COMMON MISTAKES
Forgetting [Link]().
Using a busy port like 3000 when another app is already running.
Expecting browser APIs like document or window to exist in [Link].
Q. What is localhost?
A. localhost means your own computer acting as the server.
Q. What is a port?
A. A port is a logical address where a server listens for requests, like 3000 or 5000.
PRACTICE AND CODING TASKS
[Link] 5/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Global objects are available without importing. __dirname and __filename are CommonJS
__dirname gives current folder path; globals that provide the absolute directory path
__filename gives current file path. Hinglish: Ye and absolute file path of the current module.
built-in values hain jo file location batati hain.
REAL-WORLD EXAMPLE
[Link]("Folder:", __dirname);
[Link]("File:", __filename);
USE CASE
Creating file paths for uploads, logs, templates, static files, and configuration files.
ADVANTAGES
[Link] 6/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Modules split code into reusable files. Hinglish: CommonJS uses require and [Link],
Saara code ek file me rakhna messy hota hai; while ES Modules use import and export.
modules se code clean aur reusable banta hai. [Link] supports both module systems, with
ES Modules being the modern JavaScript
standard.
REAL-WORLD EXAMPLE
// CommonJS: [Link]
function add(a, b) {
return a + b;
}
[Link] = { add };
// CommonJS: [Link]
const { add } = require("./math");
[Link](add(2, 3));
// ES Module: [Link]
export function multiply(a, b) {
return a * b;
}
// ES Module: [Link]
import { multiply } from "./[Link]";
[Link](multiply(2, 3));
USE CASE
[Link] 7/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 8/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 2
[Link] 9/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. File System: fs
The fs module lets [Link] read, create, The fs module provides APIs for interacting
update, and delete files. Hinglish: Backend ko with the file system. It supports synchronous,
files ke saath kaam karna ho to fs use hota hai. callback-based, and promise-based operations.
REAL-WORLD EXAMPLE
const fs = require("node:fs/promises");
saveNote();
USE CASE
Saving logs, reading templates, handling uploaded files, generating reports, and working with
local data.
ADVANTAGES
[Link] 10/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. Path Module
The path module creates safe file paths across The path module provides utilities for working
operating systems. Hinglish: Windows aur with file and directory paths in a cross-platform
Linux ke paths different hote hain; path module way.
app ko portable banata hai.
REAL-WORLD EXAMPLE
USE CASE
Upload folders, static assets, template paths, log file paths, and config files.
ADVANTAGES
COMMON MISTAKES
[Link] 11/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. OS Module
The os module gives information about the The os module provides operating-system-
machine running [Link]. Hinglish: Server ki related utility methods and properties such as
memory, CPU, platform jaisi details os module CPU info, memory, platform, and home
se milti hain. directory.
REAL-WORLD EXAMPLE
const os = require("node:os");
[Link]("Platform:", [Link]());
[Link]("Free memory:", [Link]());
[Link]("CPU cores:", [Link]().length);
USE CASE
[Link] 12/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
4. Events Module
Events let one part of the app announce [Link] uses an event-driven architecture. The
something and another part react. Hinglish: EventEmitter class allows objects to emit
Jaise doorbell bajti hai aur aap respond karte named events and register listeners for those
ho, waise event emit hota hai aur listener react events.
karta hai.
REAL-WORLD EXAMPLE
[Link]("orderPlaced", 101);
USE CASE
Notifications, logs, order events, background processing, WebSocket events, and internal app
communication.
ADVANTAGES
Q. What is EventEmitter?
A. It is a [Link] class used to create, emit, and listen to custom events.
Q. What is event-driven programming?
A. It is a style where actions happen in response to events.
PRACTICE AND CODING TASKS
[Link] 13/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
5. Buffers
Buffers store raw binary data. Hinglish: Text ke A Buffer is a [Link] object used to handle
alawa images, PDFs, videos binary data hote binary data directly in memory, especially while
hain; Buffer unhe memory me handle karta hai. working with streams, files, and network
packets.
REAL-WORLD EXAMPLE
[Link](buffer);
[Link]([Link]());
USE CASE
File uploads, image processing, network data, streams, and binary protocols.
ADVANTAGES
[Link] 14/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
6. Streams
Streams process data piece by piece instead of Streams are abstractions for reading or writing
loading everything at once. Hinglish: Puri data sequentially in chunks. They are memory-
movie ek saath download karne ke bajay efficient for large files and continuous data.
chunks me play hoti hai; stream bhi aisa hi
karta hai.
REAL-WORLD EXAMPLE
const fs = require("node:fs");
[Link]("end", () => {
[Link]("Finished reading");
});
USE CASE
Video streaming, large file upload/download, CSV processing, logs, and compressed file
pipelines.
ADVANTAGES
Memory efficient.
Handles large files smoothly.
Supports pipe-based data flow.
COMMON MISTAKES
Q. What is a stream?
A. A stream is a way to process data chunk by chunk.
Q. What is pipe?
A. pipe connects a readable stream to a writable stream.
PRACTICE AND CODING TASKS
[Link] 15/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 16/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 3
Async JavaScript
Master callbacks, promises, async/await, and practical error handling.
[Link] 17/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Callbacks
REAL-WORLD EXAMPLE
USE CASE
Older [Link] APIs, event handlers, timers, and custom async logic.
ADVANTAGES
COMMON MISTAKES
Create a function that returns user data after 1 second using a callback.
Add error handling for invalid user id.
Rewrite the flow with two nested async steps.
[Link] 18/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. Promises
REAL-WORLD EXAMPLE
function getProduct(id) {
return new Promise((resolve, reject) => {
if (!id) reject(new Error("Product id required"));
resolve({ id, name: "Laptop" });
});
}
getProduct(10)
.then((product) => [Link](product))
.catch((error) => [Link]([Link]));
USE CASE
Database calls, HTTP requests, file operations, payment APIs, and third-party services.
ADVANTAGES
[Link] 19/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. Async/Await
async/await makes promise code look like async/await is syntactic sugar over Promises.
normal step-by-step code. Hinglish: Promise An async function returns a Promise, and await
code ko readable banane ka modern tareeka pauses execution inside that function until the
async/await hai. Promise settles.
REAL-WORLD EXAMPLE
const fs = require("node:fs/promises");
readConfig();
USE CASE
Modern Express controllers, database queries, API calls, authentication, and file uploads.
ADVANTAGES
[Link] 20/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Error handling means catching failures and Asynchronous errors can be handled using
responding safely. Hinglish: App crash karne ke callbacks, promise catch handlers, or try/catch
bajay error ko handle karke proper response with async/await. Proper error handling
dena. prevents crashes and improves API reliability.
REAL-WORLD EXAMPLE
USE CASE
API controllers, database queries, token validation, payment callbacks, file upload failures.
ADVANTAGES
[Link] 21/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 22/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 4
[Link] 23/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. npm
npm is used to install and manage packages. npm is the default package manager for
Hinglish: Ready-made libraries install karne ke [Link]. It manages dependencies, scripts,
liye npm use hota hai. package metadata, and package publishing.
REAL-WORLD EXAMPLE
npm init -y
npm install express
npm install nodemon --save-dev
USE CASE
Installing Express, Mongoose, bcrypt, jsonwebtoken, multer, dotenv, cors, helmet, and testing
tools.
ADVANTAGES
[Link] 24/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. npx
npx runs package commands without manually npx is a package runner that executes binaries
installing them globally. Hinglish: Temporary ya from local dependencies or remote packages
project command run karni ho to npx kaam without requiring global installation.
aata hai.
REAL-WORLD EXAMPLE
USE CASE
Running project tools, generators, test runners, and one-time package commands.
ADVANTAGES
[Link] 25/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] stores project information, [Link] is the manifest file for a [Link]
dependencies, and commands. Hinglish: Ye project. It defines metadata, dependencies,
project ka ID card plus command center hai. scripts, module type, and package
configuration.
REAL-WORLD EXAMPLE
{
"name": "blog-api",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "nodemon src/[Link]",
"start": "node src/[Link]"
},
"dependencies": {
"express": "^5.0.0"
}
}
USE CASE
Running dev server, tests, linting, builds, migrations, and deployment commands.
ADVANTAGES
[Link] 26/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Libraries save time by providing tested code for Third-party libraries are installed through npm
common problems. Hinglish: Har cheez khud and imported into the project to provide
se banana zaroori nahi; package use karo jab reusable functionality such as routing,
reliable ho. validation, authentication, and database
access.
REAL-WORLD EXAMPLE
[Link](3000);
USE CASE
Using Express for servers, Mongoose for MongoDB, bcrypt for password hashing, jsonwebtoken
for JWT, and multer for uploads.
ADVANTAGES
Faster development.
Community-tested solutions.
Less boilerplate.
Focus on business logic.
COMMON MISTAKES
Install express.
Create a basic server.
Uninstall and reinstall a harmless package to understand package management.
[Link] 27/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 28/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 5
[Link]
Build real REST APIs using routes, middleware, request/response handling, and clean controller
logic.
[Link] 29/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Express makes it easier to create servers and [Link] is a minimal and flexible [Link]
APIs. Hinglish: Raw http module se kaam ho web framework used for building web servers,
sakta hai, lekin Express backend banana fast REST APIs, middleware pipelines, and
aur clean kar deta hai. backend applications.
REAL-WORLD EXAMPLE
[Link](3000, () => {
[Link]("Server running on port 3000");
});
USE CASE
REST APIs, admin backends, authentication systems, microservices, and server-rendered apps.
ADVANTAGES
Simple routing.
Middleware support.
Huge ecosystem.
Production-proven.
COMMON MISTAKES
Forgetting [Link].
Forgetting [Link] for JSON bodies.
Keeping all logic in [Link].
INTERVIEW QUESTIONS WITH ANSWERS
[Link] 30/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. Routing
Routing decides what response to send for Routing maps HTTP methods and paths to
each URL and HTTP method. Hinglish: Kaunsi handler functions. Express supports route
URL par kaunsa kaam hoga, ye route decide parameters, query strings, and modular
karta hai. routers.
REAL-WORLD EXAMPLE
USE CASE
User routes, product routes, order routes, auth routes, blog routes, and admin routes.
ADVANTAGES
Q. What is [Link]?
A. It contains route parameters like /users/:id.
Q. What is [Link]?
A. It contains query string values like /users?page=1.
PRACTICE AND CODING TASKS
[Link] 31/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. Middleware
Middleware runs between request and Middleware functions have access to req, res,
response. Hinglish: Request aane ke baad final and next. They can execute code, modify
route se pehle kuch checks ya changes karne request/response objects, end the cycle, or
hain, middleware use hota hai. pass control to the next middleware.
REAL-WORLD EXAMPLE
[Link]([Link]());
[Link](logger);
USE CASE
Logging, authentication, validation, CORS, JSON parsing, error handling, and rate limiting.
ADVANTAGES
Q. What is next?
A. next passes control to the next middleware or route handler.
Q. Can middleware end a request?
A. Yes, it can send a response and stop the pipeline.
PRACTICE AND CODING TASKS
[Link] 32/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
req contains incoming data; res sends output Express request and response objects wrap
back to the client. Hinglish: Client kya bhej raha Node's HTTP objects and provide helpers for
hai wo req me, server kya bhej raha hai wo res reading parameters, body, headers, cookies,
se. and sending responses.
REAL-WORLD EXAMPLE
if (!email || !password) {
return [Link](400).json({ message: "Email and password required" });
}
USE CASE
Reading form data, JSON body, query filters, auth headers, and sending status codes.
ADVANTAGES
Q. What is [Link]?
A. It contains parsed request body data, usually JSON.
Q. What is [Link](201)?
A. It sets HTTP status code 201, commonly used for created resources.
PRACTICE AND CODING TASKS
[Link] 33/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
REST APIs use HTTP methods to perform A REST API exposes resources through
CRUD operations on resources. Hinglish: stateless HTTP endpoints using standard
Users, blogs, products jaise resources par methods such as GET, POST, PUT/PATCH,
GET, POST, PUT, DELETE operations. and DELETE.
REAL-WORLD EXAMPLE
USE CASE
Backend APIs for mobile apps, web apps, dashboards, and third-party integrations.
ADVANTAGES
Q. What is CRUD?
A. Create, Read, Update, Delete.
Q. Difference between PUT and PATCH?
A. PUT usually replaces a full resource; PATCH updates part of a resource.
PRACTICE AND CODING TASKS
[Link] 34/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 35/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 6
[Link] 36/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. MongoDB
REAL-WORLD EXAMPLE
USE CASE
Blogs, ecommerce, user profiles, chat apps, analytics events, and rapidly changing product data.
ADVANTAGES
Flexible schema.
JSON-like data format.
Easy to use with JavaScript.
Scales well for many app types.
COMMON MISTAKES
Q. What is a collection?
A. A collection is a group of MongoDB documents, similar to a table conceptually.
Q. What is a document?
A. A document is a JSON-like record stored in MongoDB.
PRACTICE AND CODING TASKS
[Link] 37/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. Mongoose
Mongoose helps [Link] talk to MongoDB Mongoose is an ODM for MongoDB and
using schemas and models. Hinglish: [Link]. It provides schemas, models,
MongoDB ke flexible data ko proper structure validation, middleware, and query helpers.
dene ke liye Mongoose use hota hai.
REAL-WORLD EXAMPLE
[Link]([Link].MONGO_URI);
USE CASE
Defining users, posts, products, orders, comments, roles, and validation rules.
ADVANTAGES
Schema validation.
Cleaner database code.
Built-in model methods.
Middleware hooks.
COMMON MISTAKES
Q. What is ODM?
A. Object Document Mapper. It maps application objects to MongoDB documents.
Q. What is a Mongoose model?
A. A model is a class-like wrapper used to create and query documents.
PRACTICE AND CODING TASKS
[Link] 38/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. CRUD Operations
CRUD means create, read, update, and delete CRUD operations are the basic database
data. Hinglish: Database me data add, dekhna, operations used to create, retrieve, update, and
change, delete karna. delete records.
REAL-WORLD EXAMPLE
// Create
const user = await [Link]({ name: "Aman", email: "aman@[Link]" });
// Read
const users = await [Link]();
const singleUser = await [Link](user._id);
// Update
const updated = await [Link](user._id, { name: "Aman Sharma" }, { new: true });
// Delete
await [Link](user._id);
USE CASE
Every real app: users, blogs, products, carts, comments, orders, invoices.
ADVANTAGES
[Link] 39/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Schema defines shape of data; model is used A Mongoose schema defines document
to interact with the collection. Hinglish: Schema structure, validations, defaults, and options. A
rules batata hai, model database se baat karta model provides an interface for creating and
hai. querying documents.
REAL-WORLD EXAMPLE
USE CASE
Enforcing structure for user accounts, blog posts, orders, products, and permissions.
ADVANTAGES
COMMON MISTAKES
Q. What is trim?
A. It removes extra spaces from the beginning and end of strings.
PRACTICE AND CODING TASKS
[Link] 40/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
5. Basic Relations
Relations connect one document to another. MongoDB relations are commonly represented
Hinglish: Blog post kis user ne likha, ye relation using embedded documents or references.
se store hota hai. Mongoose supports references through
ObjectId and populate.
REAL-WORLD EXAMPLE
USE CASE
[Link] 41/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 42/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 7
Authentication
Build signup/login using bcrypt password hashing and JWT-based protected routes.
[Link] 43/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Signup System
Signup creates a new user account. Hinglish: A signup flow validates user input, checks for
User email/password dekar account banata existing accounts, hashes the password, and
hai. stores the user securely in the database.
REAL-WORLD EXAMPLE
USE CASE
User registration in apps, dashboards, ecommerce, SaaS products, and admin systems.
ADVANTAGES
COMMON MISTAKES
[Link] 44/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
bcrypt converts passwords into secure hashes. bcrypt is a password-hashing library that
Hinglish: Password database me original form applies salting and computational cost to make
me nahi rakhna; hash form me store karna hai. password cracking harder.
REAL-WORLD EXAMPLE
USE CASE
Hash a password.
Compare correct password.
Compare wrong password.
[Link] 45/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. Login System
Login verifies email and password, then gives A login flow finds the user by email, compares
access. Hinglish: User ki identity check karni the submitted password with the stored hash,
hoti hai. and returns an authentication token or session.
REAL-WORLD EXAMPLE
USE CASE
Giving different errors for wrong email and wrong password, which can leak user existence.
Using weak JWT secret.
Sending token over insecure HTTP in production.
INTERVIEW QUESTIONS WITH ANSWERS
[Link] 46/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
4. JWT Authentication
JWT is a signed token used to prove the user is JSON Web Token is a compact, URL-safe
logged in. Hinglish: Token ek digital pass hai jo token format used to transmit signed claims
protected routes me bheja jata hai. between parties. In APIs, JWTs are often used
for stateless authentication.
REAL-WORLD EXAMPLE
try {
const decoded = [Link](token, [Link].JWT_SECRET);
[Link] = decoded;
next();
} catch {
[Link](401).json({ message: "Invalid token" });
}
}
USE CASE
Protected routes, mobile app auth, SPA auth, role checks, API-to-API communication.
ADVANTAGES
Stateless authentication.
Works well across frontend and backend.
Can include expiry.
Good for distributed APIs.
COMMON MISTAKES
[Link] 47/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 48/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 8
File Upload
Accept image/file uploads using Multer and store metadata safely.
[Link] 49/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Multer Usage
Multer helps Express handle multipart/form- Multer is Express middleware for handling
data file uploads. Hinglish: Browser/Postman multipart/form-data, primarily used for file
se file bhejne par Express directly file read nahi uploads. It can store files in memory or on disk.
kar pata; Multer help karta hai.
REAL-WORLD EXAMPLE
USE CASE
Profile pictures, blog images, product photos, resumes, PDFs, and documents.
ADVANTAGES
Q. What is multipart/form-data?
A. It is the content type used by forms when uploading files.
Q. What does [Link]('image') mean?
A. It expects one uploaded file under the field name image.
PRACTICE AND CODING TASKS
[Link] 50/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Install multer.
Create POST /upload.
Upload one image using Postman.
[Link] 51/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
An image upload API accepts an image, stores An image upload endpoint validates the
it, and returns its URL or filename. Hinglish: incoming file, stores it in local or cloud storage,
Frontend image bhejta hai, backend save and persists metadata such as filename, path,
karke file ka reference return karta hai. MIME type, and owner.
REAL-WORLD EXAMPLE
USE CASE
User avatars, product galleries, blog cover images, KYC uploads, and CMS media.
ADVANTAGES
[Link] 52/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 53/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 9
[Link] 54/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Try/Catch
try/catch catches errors so the app can try/catch is used to handle synchronous errors
respond safely. Hinglish: Agar code fail ho jaye, and awaited promise rejections inside async
app crash na ho; error handle ho jaye. functions.
REAL-WORLD EXAMPLE
USE CASE
Prevents crashes.
Makes failures predictable.
Works well with global error middleware.
COMMON MISTAKES
[Link] 55/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
A global error handler sends one standard error Express error-handling middleware has four
format for the whole app. Hinglish: Har route parameters: err, req, res, and next. It
me alag-alag error response likhne ke bajay centralizes error responses and logging.
centralized error handler.
REAL-WORLD EXAMPLE
[Link]([Link] || 500).json({
success: false,
message: [Link] || "Internal Server Error"
});
});
USE CASE
Consistent API errors, logging, validation errors, database errors, and production-safe messages.
ADVANTAGES
Cleaner controllers.
Consistent error response format.
Central place for logging.
Avoids leaking stack traces in production.
COMMON MISTAKES
[Link] 56/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
3. Helmet
Helmet sets secure HTTP headers. Hinglish: Helmet is Express middleware that helps
Helmet response headers ko secure banata secure apps by setting various HTTP response
hai. headers.
REAL-WORLD EXAMPLE
[Link](helmet());
USE CASE
Install helmet.
Add [Link](helmet()).
Check response headers.
[Link] 57/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
4. CORS
CORS controls which frontend origins can call CORS is a browser security mechanism. The
your backend. Hinglish: Backend decide karta cors middleware configures Cross-Origin
hai kaunsi website se request allow hogi. Resource Sharing headers for Express APIs.
REAL-WORLD EXAMPLE
[Link](cors({
origin: "[Link]
credentials: true
}));
USE CASE
Allowing React, Angular, Vue, mobile, or admin frontend apps to call backend APIs.
ADVANTAGES
Install cors.
Allow localhost frontend origin.
Test from browser and Postman.
[Link] 58/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 59/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 10
Advanced [Link]
Organize production-level apps with architecture, environment variables, logging, and rate
limiting.
[Link] 60/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. MVC Architecture
MVC separates data, logic, and routes/views. MVC is an architectural pattern that separates
Hinglish: Code ko alag responsibilities me Model, View, and Controller responsibilities. In
divide karna taki project maintainable ho. APIs, controllers handle HTTP logic while
models handle data structure and persistence.
REAL-WORLD EXAMPLE
// routes/[Link]
[Link]("/", getUsers);
// controllers/[Link]
async function getUsers(req, res, next) {
const users = await [Link]();
[Link](users);
}
// models/[Link]
const User = [Link]("User", userSchema);
USE CASE
Medium and large backend APIs where routes, controllers, models, and services must stay
organized.
ADVANTAGES
Cleaner files.
Easier testing.
Better teamwork.
Less duplicate code.
COMMON MISTAKES
[Link] 61/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 62/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
A clean folder structure makes backend code A production [Link] project commonly
easy to find and maintain. Hinglish: Files ka separates configuration, routes, controllers,
ghar fix rakho, warna project bada hote hi services, models, middleware, utilities, and
confusion. tests.
REAL-WORLD EXAMPLE
src/
[Link]
[Link]
config/
[Link]
models/
[Link]
routes/
[Link]
controllers/
[Link]
middleware/
[Link]
utils/
[Link]
USE CASE
Blog APIs, ecommerce APIs, SaaS backends, admin dashboards, and team projects.
ADVANTAGES
Easy navigation.
Improved maintainability.
Clear ownership of logic.
Scales with features.
COMMON MISTAKES
[Link] 63/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
.env stores configuration like port, database Environment variables externalize configuration
URL, and secrets outside code. Hinglish: from application code, allowing different values
Secret values code me hard-code nahi karne; across development, testing, and production
.env me rakhne. environments.
REAL-WORLD EXAMPLE
// .env
PORT=5000
MONGO_URI=mongodb://localhost:27017/blogdb
JWT_SECRET=super-secret-change-me
// [Link]
require("dotenv").config();
const port = [Link] || 3000;
USE CASE
Database URL, JWT secret, API keys, port, environment mode, cloud credentials.
ADVANTAGES
Install dotenv.
Move PORT to .env.
Create .[Link].
[Link] 64/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
4. Logging
Logging records what is happening in the app. Logging captures application events, errors,
Hinglish: App me kya request aayi, kya error and operational data. Production apps use
hua, kya important event hua, sab logs me structured logging for debugging, monitoring,
track hota hai. and auditing.
REAL-WORLD EXAMPLE
[Link](requestLogger);
USE CASE
Debugging production issues, tracking API requests, monitoring errors, audit trails.
ADVANTAGES
Faster debugging.
Better production visibility.
Helps detect suspicious behavior.
Useful for audits.
COMMON MISTAKES
[Link] 65/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
5. Rate Limiting
Rate limiting controls how many requests a Rate limiting restricts the number of requests a
user can make. Hinglish: Ek user bahut zyada client can make in a time window, helping
requests bhej raha hai to limit laga do. protect APIs from abuse and brute-force
attacks.
REAL-WORLD EXAMPLE
[Link]("/api", limiter);
USE CASE
Login protection, public APIs, search endpoints, OTP APIs, payment routes.
ADVANTAGES
Reduces abuse.
Helps against brute-force login attempts.
Protects server resources.
Improves API reliability.
COMMON MISTAKES
Install express-rate-limit.
Limit login route to 5 requests per 15 minutes.
Return a friendly error message.
[Link] 66/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 67/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 11
Performance
Understand scaling basics through clustering and caching.
[Link] 68/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Clustering
Clustering runs multiple [Link] workers to use The [Link] cluster module allows creating
multiple CPU cores. Hinglish: Node ek main JS child worker processes that share the same
thread use karta hai; cluster se multiple server port, helping utilize multiple CPU cores.
workers bana kar CPU cores use kar sakte
hain.
REAL-WORLD EXAMPLE
if ([Link]) {
const cores = [Link]().length;
for (let i = 0; i < cores; i++) [Link]();
} else {
const app = express();
[Link]("/", (req, res) => [Link]("Worker " + [Link]));
[Link](3000);
}
USE CASE
[Link] 69/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
2. Caching Basics
REAL-WORLD EXAMPLE
USE CASE
Product lists, public blog posts, settings, category lists, expensive calculations.
ADVANTAGES
Faster responses.
Less database load.
Better scalability.
Improves user experience.
COMMON MISTAKES
[Link] 70/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 71/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
MODULE 12
[Link] 72/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
1. Project Overview
We will build a Blog API with users, A production-ready Blog API demonstrates
authentication, protected posts, image upload, REST design, authentication, database
and clean folder structure. Hinglish: Ye real modeling, middleware, error handling, security
interview/project-level backend hoga. configuration, and deployable project structure.
REAL-WORLD EXAMPLE
Features:
- Signup and login
- JWT protected routes
- Create, read, update, delete blogs
- Upload blog cover image
- MongoDB with Mongoose
- Global error handler
- Helmet, CORS, rate limiting
- Environment variables
USE CASE
COMMON MISTAKES
[Link] 73/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
REAL-WORLD EXAMPLE
blog-api/
src/
[Link]
[Link]
config/
[Link]
controllers/
[Link]
[Link]
middleware/
[Link]
[Link]
[Link]
models/
[Link]
[Link]
routes/
[Link]
[Link]
utils/
[Link]
[Link]
uploads/
.[Link]
[Link]
USE CASE
Professional structure.
Easy debugging.
Easy feature expansion.
Interview-friendly.
COMMON MISTAKES
[Link] 74/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 75/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Create Express app, connect database, and Separating app initialization from server startup
start server. Hinglish: App setup aur server improves testability and keeps infrastructure
start ko clean tarike se alag rakho. concerns isolated.
REAL-WORLD EXAMPLE
// src/[Link]
const express = require("express");
const helmet = require("helmet");
const cors = require("cors");
[Link](helmet());
[Link](cors({ origin: [Link].CLIENT_URL }));
[Link]([Link]());
[Link]("/api/auth", require("./routes/[Link]"));
[Link]("/api/blogs", require("./routes/[Link]"));
[Link](require("./middleware/[Link]"));
[Link] = app;
// src/[Link]
require("dotenv").config();
const app = require("./app");
const connectDB = require("./config/db");
connectDB().then(() => {
[Link]([Link] || 5000, () => {
[Link]("Server started");
});
});
USE CASE
Clean startup.
Easy testing.
Configurable environments.
Centralized middleware setup.
COMMON MISTAKES
[Link] 76/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 77/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Models define data; routes expose operations. Blog CRUD requires a schema with author
Hinglish: Blog data ka structure model me, API references and controller endpoints that
endpoints routes/controllers me. enforce authentication, authorization,
validation, and consistent responses.
REAL-WORLD EXAMPLE
USE CASE
User-generated content, CMS, portfolio blogs, posts, articles, and admin publishing.
ADVANTAGES
[Link] 78/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
[Link] 79/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
5. Production Checklist
Before sharing or deploying, check security, A production-ready [Link] API should include
config, errors, and documentation. Hinglish: environment configuration, secure headers,
Sirf code chalna enough nahi; production validation, authentication, centralized errors,
readiness bhi chahiye. logging, rate limiting, documentation, and
deployment scripts.
REAL-WORLD EXAMPLE
Checklist:
- .[Link] exists
- .env is ignored by Git
- Helmet enabled
- CORS configured
- Auth routes rate-limited
- Passwords hashed
- JWT secret strong
- Global error handler
- Request validation
- README with API endpoints
- npm start script
- Logs do not expose secrets
USE CASE
[Link] 80/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
Create [Link].
Add endpoint table.
Add .[Link].
Test every route after restarting the server.
[Link] 81/82
5/6/26, 12:13 PM [Link] Job-ready Complete Course
FINAL REVISION
[Link] 82/82