Express.js Basics: Routing & API Development

🚀 Today I Learned: Express.js Basics (Hands-On Practice) Today, I explored Express.js, a fast and minimal Node.js framework used to build backend APIs and web servers. 🔹 Created an Express server 🔹 Implemented multiple routes 🔹 Used route parameters (:id) 🔹 Learned how optional parameters (?) work 🔹 Sent JSON responses using res.send() 🔹 Started server using app.listen() 📌 Example: /about → returns user data /about/:id/user → dynamic routing /content-page → different API endpoint / → home route const express = require("express"); ✅ Code Example: const app = express(); /* About Route */ app.use("/about", (req, res) => { res.send({ name: "Rahul", age: 24, money: 60 }); }); /* Route with Optional Parameter */ app.use("/about/:id?/user", (req, res) => { console.log(req.params); // { id: 'value' } or {} res.send({ name: "Rahul", age: 24, money: 60 }); }); /* Content Page Route */ app.use("/content-page", (req, res) => { res.send({ name: "Vikash", age: 23, money: 80 }); }); /* Home Route */ app.use("/", (req, res) => { res.send("I am at Home page"); }); /* Server Listening */ app.listen(4000, () => { console.log("🚀 Server running on port 4000"); }); This helped me understand routing, request handling, and API structure in real backend development. Backend learning in progress 🚀 Next goal: GET vs POST, Middleware & REST API #ExpressJS #NodeJS #BackendDevelopment #WebDevelopment #LearningByDoing #RahulJangra

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories