Forwarded from Channel Unwrapped
Channel Summary for 2025 π
Views
β’ 290 Total Posts
β’ 90 Average Views
β’ 26,367 Total Views
Top Post
β’ 1,337 Views
β’ https://t.me/fullstackCampp/158
Activity
β’ 6 AM is when you were most active
β’ Monday is your most active day
β’ July is your most active month
@channel_unwrapped_bot
Views
β’ 290 Total Posts
β’ 90 Average Views
β’ 26,367 Total Views
Top Post
β’ 1,337 Views
β’ https://t.me/fullstackCampp/158
Activity
β’ 6 AM is when you were most active
β’ Monday is your most active day
β’ July is your most active month
@channel_unwrapped_bot
β€3
π Week 7 Day 7 β Express Router & Useful NPM Packages
Alright campers π₯π
I hope youβre rested, hydrated, and still coding with curiosity. I apologize for not posting these weeks-life happened.
Today is our last lesson for Express basics before we move to even bigger things.
π³ BIG IDEA:
When your project grows, all your routes in app.js become messy and hard to manage.
π The solution?
π¦ Modularization
π£οΈ Express Router
Just like a house has many rooms, your Express app should have many route files, not one chaotic room.
π§ 1οΈβ£ Why Router?
β οΈ PROBLEM: When your application grows:
ο»Ώ
All inside app.jsβ¦
It becomes a mess π΅
π§ Router allows you to split routes into logical files:
s
Each file handles only one thing β clean, organized code.
π οΈ 2οΈβ£ Create a Router
π Step 1: Create a folder
π Step 2: Create users.js
π Step 3: Use it in app.js
π Now:
GET /users β gets all users
POST /users β creates new user
πͺ Cleaner, better, scalable.
π¦ 3οΈβ£ Another Example: posts.
er;
In app
Now you have:
/posts
/posts/123
π‘ This is URL prefixing.
β¨ 4οΈβ£ Benefits of Router
π₯ 1. Clean code
π₯ 2. Easier debugging
π₯ 3. Can handle large projects
π₯ 4. Can assign middleware per router
π₯ 5. Can add separate controllers later
Imagine running a restaurant:
βKitchen
βCashier
βDelivery
βCleaning
Each has their own place.
Same for routes.
π― Very Useful Pattern
Structure:
Later we will move logic from routes β controllers.
π§° 5οΈβ£ NPM Packages Commonly Used with Express
Below are must-know tools.
Youβll use them in almost every real backend.
1οΈβ£ morgan β Logging requests
Shows every request in console:
β
Install:
Use:
2οΈβ£ cors β Cross Origin Resource Sharing
Frontend and backend are different origins.
If frontend is: http://localhost:5173 Backend is: http://localhost:3000
Browser blocks requests β unless we allow.
Install:
Use:
3οΈβ£ uuid β Unique IDs
Instead of inventing IDs:
Every new resource gets a unique identifier.
4οΈβ£ dotenv β Environment Variables
Instead of writing this in code:
Put it in .env:
Load it:
Use it:
5οΈβ£ nodemon β Auto restart server β€οΈ
When you save file β server restarts automatically.
Install:
Run:
This saves hours of pain.
π Documentation
π Express Router: https://expressjs.com/en/guide/routing.html
π Morgan: https://www.npmjs.com/package/morgan
π CORS: https://www.npmjs.com/package/cors
Alright campers π₯π
I hope youβre rested, hydrated, and still coding with curiosity. I apologize for not posting these weeks-life happened.
Today is our last lesson for Express basics before we move to even bigger things.
π³ BIG IDEA:
When your project grows, all your routes in app.js become messy and hard to manage.
π The solution?
π¦ Modularization
π£οΈ Express Router
Just like a house has many rooms, your Express app should have many route files, not one chaotic room.
π§ 1οΈβ£ Why Router?
β οΈ PROBLEM: When your application grows:
app.get('/users')
app.post('/users')
app.get('/posts')
app.delete('/posts/:id')
app.put('/products/:id') ... ο»Ώ
All inside app.jsβ¦
It becomes a mess π΅
π§ Router allows you to split routes into logical files:
routes/users.js
routes/posts.js
routes/products.j
s
Each file handles only one thing β clean, organized code.
π οΈ 2οΈβ£ Create a Router
π Step 1: Create a folder
/routes π Step 2: Create users.js
const express = require("express");
const router = express.Router();
// Routes
router.get("/", (req, res) => {
res.send("Get all users"); });
router.post("/", (req, res) => {
res.send("Create new user"); });
module.exports = router; π Step 3: Use it in app.js
;
const usersRoute = require("./routes/users");
app.use("/users", usersRoute)
π Now:
GET /users β gets all users
POST /users β creates new user
πͺ Cleaner, better, scalable.
π¦ 3οΈβ£ Another Example: posts.
js
const express = require("express");
const router = express.Router();
router.get("/", (req, res) => {
res.send("All posts"); });
router.get("/:id", (req, res) => {
res.send("Single post with ID " + req.params.id); });
module.exports = rout
er;
In app
.js:ute);
const postsRoute = require("./routes/posts");
app.use("/posts", postsRo
Now you have:
/posts
/posts/123
π‘ This is URL prefixing.
β¨ 4οΈβ£ Benefits of Router
π₯ 1. Clean code
π₯ 2. Easier debugging
π₯ 3. Can handle large projects
π₯ 4. Can assign middleware per router
π₯ 5. Can add separate controllers later
Imagine running a restaurant:
βKitchen
βCashier
βDelivery
βCleaning
Each has their own place.
Same for routes.
π― Very Useful Pattern
Structure:
project/
β app.js
β package.json
β
ββ routes/
β
ββ users.js
β
ββ posts.js
β
ββ controllers/
ββ usersController.js
ββ postsController.js Later we will move logic from routes β controllers.
π§° 5οΈβ£ NPM Packages Commonly Used with Express
Below are must-know tools.
Youβll use them in almost every real backend.
1οΈβ£ morgan β Logging requests
Shows every request in console:
β
GET /users 200 12ms
β POST /login 401 5ms Install:
npm install morgan Use:
const morgan = require("morgan"); app.use(morgan("dev")); 2οΈβ£ cors β Cross Origin Resource Sharing
Frontend and backend are different origins.
If frontend is: http://localhost:5173 Backend is: http://localhost:3000
Browser blocks requests β unless we allow.
Install:
npm install cors Use:
const cors = require("cors"); app.use(cors()); 3οΈβ£ uuid β Unique IDs
Instead of inventing IDs:
const { v4: uuid } = require("uuid"); const user = { id: uuid(), name: "John" }; Every new resource gets a unique identifier.
4οΈβ£ dotenv β Environment Variables
Instead of writing this in code:
const PORT = 3000; Put it in .env:
PORT=3000 DATABASE_URL=... Load it:
require("dotenv").config(); Use it:
app.listen(process.env.PORT); 5οΈβ£ nodemon β Auto restart server β€οΈ
When you save file β server restarts automatically.
Install:
npm install -g nodemon Run:
nodemon app.js This saves hours of pain.
π Documentation
π Express Router: https://expressjs.com/en/guide/routing.html
π Morgan: https://www.npmjs.com/package/morgan
π CORS: https://www.npmjs.com/package/cors
Expressjs
Express routing
Learn how to define and use routes in Express.js applications, including route methods, route paths, parameters, and using Router for modular routing.
π₯Week 7 Day 7 challenges
π§© Challenge 1: Modular Blog API
π Build a small blog API using Express Router.
Requirements:
Create routes folder
ποΈ posts.js
ποΈ authors.js
Each file should export a router
Main app.js must use them like:
Endpoints to include (just dummy responses):
β /posts/ β return list of posts
β /posts/:id β return a single post
β /authors/ β return list of authors
β /authors/:id β return author details
Add middleware:
Use morgan for request logging
Use uuid to generate post IDs
π§© Challenge 2: Notes API with Router + File Storage
π Build a simple Notes API, split into modules:
π /routes/notes.js
π /data/notes.json
Endpoints:
β GET /notes β return all notes
β POST /notes β add a new note
β DELETE /notes/:id β delete a note
Requirements:
βUse uuid to generate IDs
βUse fs to read/write JSON file
βUse express.json()` middleware
Extra:
Add CORS package so any frontend can access it
π§© Challenge 3: Student Manager
π Create Student Manager with:
π /routes/students.js
π /data/students.json
Endpoints:
β GET /students
β POST /students
β GET /students/:id
β DELETE /students/:id
Use packages:
dotenv β load PORT from .env
nodemon β auto restart
.env example:
π Optional Bonus
Add routes with Router-level middleware:
Example:
When you are done:
π₯share your solutions in the group,
π₯invite a friend,
and as always β
π₯stay well, stay curious, and stay coding βοΈ
π§© Challenge 1: Modular Blog API
π Build a small blog API using Express Router.
Requirements:
Create routes folder
ποΈ posts.js
ποΈ authors.js
Each file should export a router
Main app.js must use them like:
app.use("/posts", postsRouter); app.use("/authors", authorsRouter); Endpoints to include (just dummy responses):
β /posts/ β return list of posts
β /posts/:id β return a single post
β /authors/ β return list of authors
β /authors/:id β return author details
Add middleware:
Use morgan for request logging
Use uuid to generate post IDs
π§© Challenge 2: Notes API with Router + File Storage
π Build a simple Notes API, split into modules:
π /routes/notes.js
π /data/notes.json
Endpoints:
β GET /notes β return all notes
β POST /notes β add a new note
β DELETE /notes/:id β delete a note
Requirements:
βUse uuid to generate IDs
βUse fs to read/write JSON file
βUse express.json()` middleware
Extra:
Add CORS package so any frontend can access it
π§© Challenge 3: Student Manager
π Create Student Manager with:
π /routes/students.js
π /data/students.json
Endpoints:
β GET /students
β POST /students
β GET /students/:id
β DELETE /students/:id
Use packages:
dotenv β load PORT from .env
nodemon β auto restart
.env example:
PORT=4000 π Optional Bonus
Add routes with Router-level middleware:
Example:
router.use((req, res, next) => {
console.log("Students Router middleware running");
next(); });When you are done:
π₯share your solutions in the group,
π₯invite a friend,
and as always β
π₯stay well, stay curious, and stay coding βοΈ
Full Stack Camp pinned Β«π Welcome to Fullstack Summer Camp 2025! Learn. Build. Launch. Hey campers! π This is your one-stop space to master fullstack web development from scratch β right here on Telegram. Over the next 12 weeks, weβll dive deep into: π Frontend: HTML, CSS, JavaScriptβ¦Β»
Full Stack Camp pinned Β«Week 1 Day 1 π‘ What Is Coding? How It Works, Why It Matters, and How You Can Start π Welcome welcome welcome to Fullstack Summer Camp! α°ααααα π Today is Day 1 of our fullstack development journey. Whether you're here because you're curious, bored, orβ¦Β»
1οΈβ£ What is the main purpose of Express Router?
Anonymous Quiz
40%
a) To start the server
0%
b) To handle HTTP protocols
60%
c) To organize routes into modular files
0%
d) To replace middleware
2οΈβ£ Which line correctly creates a router instance?
Anonymous Quiz
40%
a) const router = express()
20%
b) const router = new Router()
40%
c) const router = express.Router()
0%
d) const router = require("router")
3οΈβ£ What does app.use("/users", usersRouter) do?
Anonymous Quiz
67%
a) Starts the users server
0%
b) Attaches middleware only for POST requests
33%
c) Prefixes all routes in usersRouter with /users
0%
d) Registers error middleware
4οΈβ£How do you read route parameters in Express?
Anonymous Quiz
0%
a) req.query
50%
b) req.params
50%
c) req.body
0%
d) req.route
5οΈβ£Which request URL matches this route? app.get("/products/:id")
Anonymous Quiz
67%
a) /products?id=5
33%
b) /products/5
0%
c) /product/5
0%
d) /products?id=:id
6οΈβ£What happens if you send two responses in one request?
Anonymous Quiz
0%
a) Express ignores the second one
50%
b) Server crashes
50%
c) Browser handles it
0%
d) Express throws an error
7οΈβ£Which package helps log HTTP requests?
Anonymous Quiz
100%
a) cors
0%
b) dotenv
0%
c) morgan
0%
d) uuid
8οΈβ£What problem does cors solve?
Anonymous Quiz
50%
a) Server crashes
0%
b) Cross-origin request blocking
50%
c) File uploads
0%
d) Route duplication
9οΈβ£Where should sensitive data like API keys be stored?
Anonymous Quiz
0%
a) In JavaScript files
0%
b) In package.json
100%
c) In .env file
0%
d) In routes
πHow do you set an HTTP status code in Express?
Anonymous Quiz
0%
a) res.send(404)
50%
b) res.status(404).send()
50%
c) req.status(404)
0%
d) res.code(404)
1οΈβ£1οΈβ£Which situation will cause an Express app to hang (never respond)?
Anonymous Quiz
33%
a) Sending res.json()
67%
b) Forgetting to call next() in middleware
0%
c) Using app.get()
0%
d) Forgetting express.json()
1οΈβ£2οΈβ£ What is a common mistake when using res.sendFile()?
Anonymous Quiz
0%
a) Sending JSON
100%
b) Forgetting absolute path or __dirname
0%
c) Using HTTP instead of HTTPS
0%
d) Missing headers
1οΈβ£3οΈβ£ What happens if two routes match the same request?
Anonymous Quiz
50%
a) Express throws an error
0%
b) Both routes run
50%
c) The first matching route runs
0%
d) The last route runs
1οΈβ£4οΈβ£ Which is TRUE about req.params and req.query?
Anonymous Quiz
0%
a) Both come from request body
0%
b) Both are optional URL data
50%
c) params come from route path, query from URL string
50%
d) They are identical