NOTE:- The "must_change.env" must require some changes;
> remove the word "must_change.env" and change it into ".env" only
> replace values with your own credentials inside .env file
"The journey of a thousand miles begins with one step."
-
Project Initialization
- package.json setup
- Install Express & dotenv
-
Configuration
- Create .env file (PORT)
- Build server (index.js)
-
Routing & Server
- Define GET routes (/, /login, /signup)
- Start server
"Code is like humor. When you have to explain it, itβs bad."
-
API Fundamentals
- What is an API
- Role in frontend-backend communication
-
Working with APIs in React
- Fetch vs Axios comparison
- Axios GET request with then() & catch()
- Best practices (useEffect, useState, error handling)
-
Handling CORS Issues
- What is CORS
- Proxy setup in Vite
- Backend solutions (cors package, headers)
"Structure your data before you build β clean models lead to clean code."
-
Data Modeling Basics
- Object modeling purpose
- Benefits of early planning
-
Introduction to Mongoose
- What is Mongoose
- Schemas and models
-
Project Structure & Naming Conventions
models/
folder setup- File naming patterns
-
Schema Definition Essentials
- Field types and rules
- Common validations (required, unique, min, etc.)
- Timestamps for created/updated tracking
- Model Relationships: Using
ref
for associations
"Learning to write programs stretches your mind, and helps you think better."
-
Data Modeling Practice
- E-Commerce Store Schema Design
- Hospital Management System Schema Design
-
Exploring Mongoose Concepts
- Review:
models/ecommerce/
- Review:
models/hospital_management/
- Review:
"A well-structured project is the foundation of professional software development."
-
UI/UX Design & DB Planning Phase
- Design all screens using tools like Figma
- Collect data points for DB
- Create data modeling diagram (with tools like Eraser.io)
-
Project Initialization & Structuring
- Initialize
package.json
withnpm init
- Setup common folders:
src
,public
,controllers
,routes
, etc. - Create essential files:
.env
,.gitignore
,README.md
, etc.
- Initialize
-
Development Tools Setup
- Install
nodemon
for auto-restart - Install
prettier
for consistent formatting
- Install
-
Files Configuration
- Use online generator to create
.gitignore
for Node.js - Add
.prettierrc
and.prettierignore
files - Update
package.json
for modules and scripts
- Use online generator to create
"Build software the way real teams do β step by step, piece by piece."
-
MongoDB Atlas
- Create account, project, cluster
- Save URI in
.env
-
DB Connection
- Two connection approaches:
Direct connect in
index.js
(less modular) Usesrc/db/connection.js
- Best Practices: Use
async/await
+try/catch
- Two connection approaches:
Direct connect in
-
Import Rules
- Load
dotenv
at top of entry file - Add
.js
extension to imports - Keep secrets in
.env
- Keep
index.js
clean
- Load
"Building real-world back-end architecture step by step."
-
Express App Setup (
app.js
)- Middlewares:
cors
,cookieParser
,express.json
, etc.
- Middlewares:
-
Server Initialization (
index.js
)- DB connection, server start, and error handling
- DB connection, server start, and error handling
-
Utility Modules (
utils/
)asyncHandler.js
β async error wrapperApiError.js
β custom error classApiResponse.js
β consistent success responses
"Professional backend development through real-world modeling techniques."
-
Model Structure & Setup
- Created
user.model.js
andvideo.model.js
using Mongoose - Used ObjectId references, timestamps, and schema validation
- Created
-
User Model & Authentication
- Defined user fields
- Password hashing with
bcrypt
using Mongoose pre-save middleware - Custom methods for authentication:
- Password verification (
bcrypt
) - JWT generation (
jsonwebtoken
) for access & refresh tokens
- Password verification (
- Stored secrets and token expiry settings in
.env
-
Video Model & Pagination
- Defined video fields
- Linked each video to its owner (User)
- Added pagination support using
mongoose-aggregate-paginate-v2
"Code is the bridge between imagination and reality; every bug you fix is a step forward."
-
Cloudinary Setup
- Creating an account and adding credentials in
.env
- Installing npm package
cloudinary
and configure - Functions to upload files and handle errors
- Creating an account and adding credentials in
-
Multer Setup
- Installing npm package
multer
- Define multer as middleware
- Multer uses for temporary file storage, and works with Cloudinary
- Installing npm package
"The web speaks in protocols β learn their language to unlock endless possibilities."
-
HTTP Basics
- Overview
- HTTP vs HTTPS
- Client-Server Model
- URL, URI, URN
-
HTTP Headers
- Purpose and importance
- Types: Request, Response, Representation, Payload
- Key headers: Authorization, Content-Type, CORS
-
HTTP Methods
- Main verbs: GET, POST, PUT, PATCH, DELETE
- Others: HEAD, OPTIONS, TRACE
-
HTTP Status Codes
- Categories: 1xx to 5xx
- Common codes: 200, 201, 400, 401, 403, 404, 500
"Building like a pro β following real-world back-end development practices."
-
Express Router & Route Management
- Using Express Router
- Exporting and importing router in
app.js
- Mounting routes with
app.use()
-
Controller Functions & JSON Responses
- Writing controller functions
- Sending JSON responses with status codes
- Example:
registerUser
controller returning a success message
-
Error Handling with
asyncHandler
- Wrapping controllers to handle async errors
- Avoiding repetitive try-catch blocks
- Passing errors to Express using
next(error)
-
API Testing with Postman
- Creating collections and requests
- Testing POST routes like
/register
- Verifying JSON response and status codes
"Building like real professionals, one step at a time."
-
User Registration Workflow
- Input validation and duplication checks
- Image handling and upload (avatar, cover)
- User creation and sensitive data filtering
- Structured API response to frontend
-
File Management
- Local file handling with Multer
- Cloudinary integration for media uploads
-
Error Handling & API Response
- Centralized error responses using
ApiError
- Consistent success responses via
ApiResponse
- Centralized error responses using
"Building like real devs β one step at a time."
-
User Registration API
- Testing
/api/v1/users/register
using POSTMAN - Required form-data fields: fullName, email, username, password, avatar, coverImage
- Backend tasks: validation, duplication checks, Cloudinary upload, DB save, response handling
- Testing
-
Cloudinary Bug Fixes
- Bug in
cloudinary.js
due to delayeddotenv.config()
- Environment variables not loading (
CLOUDINARY_CLOUD_NAME
, etc.) - Fixes applied in:
src/index.js
(moveddotenv.config()
above imports)package.json
(nodemon -r dotenv/config ...
)
- Bug in
-
Local File Cleanup After Upload
- Deleting uploaded files from
public/temp
after Cloudinary upload - Using
fs.unlinkSync()
in both success and error cases
- Deleting uploaded files from
-
Professional Use of POSTMAN
- Organizing with Collections (e.g.,
MediaTube
) and Folders (e.g.,user
) - Creating and using Environment Variables (
server
= base URL) - Replacing hardcoded URLs with
{{server}}
variable in requests
- Organizing with Collections (e.g.,
"Building a real-world back-end system using professional development practices."
-
Authentication Flow
/login
Route/logout
RouteloginUser
ControllerlogoutUser
Controller
-
Token Management
- Access & Refresh Token Generator
- Sending Tokens as Secure Cookies
- Removing Tokens via Cookies on Logout
-
Security Middleware
verifyJWT
Middleware for Protected Routes- Token Validation via Cookies or Headers
"Simulating a real-world back-end development process used in professional software companies."
-
Authentication Route Testing
- Testing
/login
and/logout
using POSTMAN - Expected request structure and responses
- Cookie handling for tokens
- Testing
-
Login Controller Debugging
- Common login issues (missing fields, invalid credentials, etc.)
- Proper use of async/await and error handling
- Security tips: avoid exposing sensitive data
-
Token-Based Authentication
- Access Token: purpose, lifespan, and usage
- Refresh Token: role in session management and renewal
- Key differences between access and refresh tokens
- How both tokens work together in maintaining user sessions
-
Refresh Token Implementation
/refresh-token
route functionality- Validating refresh tokens and issuing new tokens
- Security practices: HttpOnly cookies, database checks
- Frontend behavior on token expiration
"Building a scalable backend by following real-world development practices."
-
Subscription Model
- Mongoose schema for user-to-user subscriptions
- Fields:
subscriber
,channel
(both linked to User model) - Includes timestamps for creation and updates
-
User Account Management
-
Password Management:
Change current password with verification -
Profile Information:
Get current logged-in user details Update full name and email (excluding password) -
Media Uploads:
Update user avatar (profile picture) Update cover image (banner)
-
"Note:- You can see the 'day 17.png' image for visual understanding"
-
Designing the Subscription Model
- Purpose of the Subscription Model
- Why not use arrays in the User schema
- One subscription per document structure
- Advantages of this Approach
-
Querying Subscriptions
- Counting a channelβs subscribers
- Listing channels a user has subscribed to
"Building real-world features using professional backend practices."
-
MongoDB Aggregation Pipeline
- What is Aggregation Pipeline
- Why and when to use it
- Benefits for complex data querying
-
Aggregation Stages
$match
β Filter documents$lookup
β Join collections$addFields
β Add or modify fields$project
β Select specific fields$sort
,$limit
,$group
,$unwind
-
Common Operators
$in
β Check if value exists in array$cond
β If-then-else logic$size
,$eq
,$and
,$or
"Building real-world back-end features, step by step, like a pro."
-
Watch History Feature
- Defining
getWatchHistory
controller - MongoDB Aggregation Pipeline usage
- Step-by-step data retrieval and joining
- Defining
-
User Routes & Structure
- Defining routes for controllers
- Public Routes:
/register
,/login
- Protected Routes:
/logout
,/history
,/update-account
, etc.
-
Route Protection & Middleware
- JWT authentication using
verifyJWT
- File upload handling with
upload
middleware
- JWT authentication using
"Expanding the backend with essential user and content models."
-
Created More Models
-
Comment
Model - content, video, owner -
Like
Model - video | comment | tweet, likedBy -
Playlist
Model - name, description, videos, owner -
Tweet
Model - content, owner
-
Simple structure, clear steps, professional workflow.
-
User Routes Tested
- Tested all
user routes
usingPostman
- Fixed small bugs
- Now user routes are working perfectly
- Tested all
-
Routes & Controllers Setup
- All routes defined in
app.js
- Created routes in
src/routes/
for:- tweet, video, comment, like, playlist, subscription, dashboard
- Created controllers in
src/controllers/
with:- Empty methods
// TASK:
comments showing what logic to add later
- All routes defined in
-
What Do Next
- Add real logic inside controller methods
- Test each route using Postman
- Make sure everything works correctly