A comprehensive Express.js learning repository covering everything from basic server creation to advanced backend concepts. This repository serves as both a revision guide and hands-on practice resource for building REST APIs and backend applications using Express.js.
This repository contains various Express.js examples and exercises that demonstrate:
- Creating Express Servers
- Routing
- Route Parameters
- Query Strings
- Request & Response Objects
- Middleware
- REST APIs
- HTTP Methods
- Error Handling
- Express Architecture
- Backend Development Fundamentals
The goal of this repository is to learn Express.js from Beginner β Intermediate β Advanced level through practical examples.
- Node.js
- Express.js
- JavaScript (ES6+)
- REST APIs
Express/
β
βββ app.js
βββ package.json
βββ routes/
βββ middleware/
βββ controllers/
βββ public/
βββ views/
βββ README.mdgit clone <repository-url>cd Expressnpm installnode app.jsor
nodemon app.jsconst express = require("express");
const app = express();
let port = 8080;
app.listen(port, () => {
console.log(`App is listening on port ${port}`);
});express()creates an Express application.app.listen()starts the server.- Server listens for incoming requests on specified port.
Every Express application follows:
Client Request
β
Express Server
β
Route Handler
β
Response Sent
Example:
app.get("/", (req, res) => {
res.send("Hello Express");
});Routing determines how an application responds to a specific client request.
app.get("/", (req, res) => {
res.send("Home Page");
});Route Parameters allow dynamic URLs.
Example:
app.get("/:username/:id", (req, res) => {
let { username, id } = req.params;
let htmlStr =
`<h1>Welcome to the page of ${username}</h1>`;
res.send(htmlStr);
});http://localhost:8080/kamlakant/101
Welcome to the page of kamlakantQuery parameters are used for searching and filtering data.
Example:
app.get("/search", (req, res) => {
console.log(req.query);
res.send("No Result");
});http://localhost:8080/search?q=apple
{
q: "apple"
}res.send("Hello World");res.send("<h1>Hello World</h1>");let username = "Kamlakant";
res.send(
`<h1>Welcome ${username}</h1>`
);The Request Object contains information sent by client.
Common Properties:
req.params
req.query
req.body
req.headers
req.method
req.urlExample:
console.log(req.query);
console.log(req.params);Used to send data back to client.
Methods:
res.send()
res.json()
res.render()
res.redirect()
res.status()Example:
res.send("Success");Instead of creating multiple routes:
β Bad
app.get("/user1");
app.get("/user2");
app.get("/user3");β Better
app.get("/:username", (req, res) => {
res.send(req.params.username);
});Used to retrieve data.
app.get("/", (req, res) => {
res.send("GET Request");
});Used to create data.
app.post("/", (req, res) => {
res.send("POST Request");
});Used to update data.
app.put("/", (req, res) => {
res.send("PUT Request");
});Used to remove data.
app.delete("/", (req, res) => {
res.send("DELETE Request");
});Middleware functions execute before route handlers.
Example:
app.use((req, res, next) => {
console.log("Middleware Executed");
next();
});- Authentication
- Logging
- Validation
- Error Handling
Catch all unmatched routes.
app.get("*", (req, res) => {
res.send("404 Page Not Found");
});Request
β
Middleware
β
Route Matching
β
Controller Logic
β
Response
- Express Installation
- Creating Server
- Routing
- Request & Response
- Route Parameters
- Query Strings
- Middleware
- REST APIs
- Dynamic Routes
- HTTP Methods
- Error Handling
- MVC Architecture
- Authentication
- Authorization
- JWT
- Database Integration
- File Upload
- Session Management
- Deployment
Express.js is a lightweight Node.js web framework used for building web applications and APIs.
Functions that execute between request and response cycle.
/user/kamal
req.params.username/search?q=apple
req.query.qRouting determines how the application responds to a specific URL request.
An API following REST principles using HTTP methods.
Used to register middleware functions.
- MongoDB Integration
- Mongoose Models
- JWT Authentication
- MVC Pattern
- RESTful APIs
- CRUD Operations
- File Uploads
- Cloudinary Integration
- Session Authentication
- Deployment on Render
After completing this repository, you will understand:
β Express Server Setup
β Routing
β Request & Response Handling
β Dynamic URLs
β Query Parameters
β Middleware
β HTTP Methods
β REST APIs
β Backend Fundamentals
β Scalable Express Project Structure
Kamlakant Kumar
Aspiring Software Engineer | MERN Stack Developer | Java Enthusiast | DSA Practitioner
β If you found this repository useful, consider giving it a star!