🌐 Backend Basics — Node.js Express
Now you move from frontend (React) → backend (server side).
Frontend = UI, Backend = Logic + Database + APIs.
🟢 What is Node.js ❓
• Node.js is a JavaScript runtime that runs outside the browser.
• Built on Chrome V8 engine, allows JavaScript to run on server.
🧠 Why Node.js is Popular
• Same language (JS) for frontend + backend
• Fast and lightweight
• Large ecosystem (npm)
• Used in real companies
⚡ How Node.js Works
• Single-threaded, event-driven, non-blocking I/O
• Handles many requests efficiently, good for APIs, real-time apps, chat apps
📦 What is npm
• npm = Node Package Manager
• Used to install libraries, manage dependencies, run scripts
Example: npm install express
🚀 What is Express.js ❓
• Express is a minimal web framework for Node.js.
• Makes backend development easy, clean routing, easy API creation, middleware support
🧩 Basic Express Server Example
• Install Express: npm init -y, npm install express
• Create server.js:
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello Backend");
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
• Creates server, handles GET request, sends response, listens on port 3000
🔄 What is an API
• API = Application Programming Interface
• Frontend talks to backend using APIs, usually in JSON format
🧠 Common HTTP Methods (Backend)
• GET: Fetch data
• POST: Send data
• PUT: Update data
• DELETE: Remove data
⚠️ Common Beginner Mistakes
• Forgetting to install express
• Not using correct port
• Not sending response
• Confusing frontend and backend
🧪 Mini Practice Task
• Create basic Express server
• Create route /about
• Create route /api/user returning JSON
• Start server and test in browser
✅ Mini Practice Task – Solution 🌐
🟢 Step 1️⃣ Install Express
Open terminal inside project folder:
npm init -y
npm install express
✔ Creates package.json
✔ Installs Express framework
📄 Step 2️⃣ Create server.js
Create a file named server.js and add:
const express = require("express");
const app = express();
// Home route
app.get("/", (req, res) => {
res.send("Welcome to my server");
});
// About route
app.get("/about", (req, res) => {
res.send("This is About Page");
});
// API route returning JSON
app.get("/api/user", (req, res) => {
res.json({ name: "Deepak", role: "Developer", age: 25 });
});
// Start server
app.listen(3000, () => {
console.log("Server running on http://localhost:3000");
});
▶️ Step 3️⃣ Start the Server
Run in terminal:
node server.js
You should see: Server running on http://localhost:3000
🌍 Step 4️⃣ Test in Browser
Open these URLs:
• http://localhost:3000/ → Welcome message
• http://localhost:3000/about → About page text
• http://localhost:3000/api/user → JSON response
Double Tap ♥️ For More