Full Stack Camp
144 subscribers
8 photos
16 files
89 links
Fullstack Camp | Learn. Build. Launch.
Welcome to the ultimate tech adventure!
Join us for a hands-on journey through HTML, CSS, JavaScript, React, Node.js, Express & MongoDB β€” all in one place.
Download Telegram
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
❀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:
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:

const postsRoute = require("./routes/posts");
app.use("/posts", postsRo
ute);

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
πŸ’₯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:
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…»
Express review questions
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
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