A hands-on learning repository for Express.js β from native Node HTTP through structured APIs, persistence, and authentication.
Teach backend development by following one HTTP request as it gains layers each day: server β structure β database β auth. Runnable code, interactive modules, and docs live in one repo so learners can run and compare projects side by side.
Curriculum (four days): docs/CURRICULUM.md β day themes, request-flow diagrams, and glossary.
Docs index: docs/README.md
| What | Path | Day | Port |
|---|---|---|---|
| Native HTTP + minimal Express | day-1-http-and-express/ | 1 | 5000 |
| Routes + controllers | express-basics/ | 2a | 5000 |
| Layered task API (in-memory) | task-api/ | 2b | 4000 |
| MongoDB task API | task-mongo/ | 3 | 4001 |
| Auth API + React UI | auth/ | 4 | 4000 / 5173 |
| Interactive modules | interactive-learning/ | 1β4 | 6700 |
| Curriculum (public) | docs/CURRICULUM.md | β | β |
Install dependencies inside each project folder (there is no single root npm install). See Getting started below. Auth setup and demo users: day-4-auth-and-security/auth/README.md.
This repository contains a structured learning path for mastering Express.js, one of the most popular Node.js web frameworks. Whether you're just starting or looking to deepen your skills, you'll find practical projects and examples here.
We start with native Node.js HTTP server basics to understand the fundamentals, then progress through Express.js at beginner, intermediate, and advanced levels. This journey helps you appreciate why Express exists and understand the transition from raw Node.js to a professional web framework.
Native Node.js β Express Basics β Organized Structure β Advanced MVC Architecture
The progression shows you not just how to use Express, but why it's the better choice.
Folder: day-1-http-and-express/ β nodeserver.js, expressapp.js
A quick reference to native Node.js HTTP server to understand what Express simplifies (manual routing, header management, body parsing, middleware).
Folder: day-2-structured-api/express-basics/
- Basic Express server setup with
app.js - Creating your first Express application
- Understanding routing fundamentals
- Separating routes from controllers
- Handling HTTP requests and responses
- Working with middleware
- Managing user data with
data.js
Folder: express-basics with user management extension
- RESTful API development with user operations
- Organizing code with controllers and routes
- MVC (Model-View-Controller) architecture introduction
- Input validation and error handling
- CORS and security basics
- Full CRUD operations on user resources
Folder: day-2-structured-api/task-api/
- Complete MVC (Model-View-Controller) architecture
- Service-oriented architecture
- Repository pattern for data access
- Complex routing patterns
- Advanced middleware composition
- Performance optimization with logging
- Production-ready application structure
learn-express/
βββ README.md
βββ docs/
β βββ README.md
β βββ CURRICULUM.md
βββ day-1-http-and-express/ # Day 1 β nodeserver.js, expressapp.js
βββ day-2-structured-api/
β βββ express-basics/ # Day 2a
β βββ task-api/ # Day 2b (port 4000)
βββ day-3-persistence/
β βββ task-mongo/ # Day 3 (port 4001)
βββ day-4-auth-and-security/
β βββ README.md
β βββ auth/
β βββ task-with-auth/
β βββ task-with-auth-ui/
βββ interactive-learning/
- Node.js (v14 or higher)
- npm or yarn package manager
- Basic JavaScript knowledge
-
Clone the repository:
git clone https://github.com/Ndevu12/learn-express.git cd learn-express -
Day 1 β HTTP and Express:
cd day-1-http-and-express node nodeserver.js # one terminal node expressapp.js # another β port 5000
Guide: day-1-http-and-express/README.md.
-
Express Basics (Day 2a):
cd day-2-structured-api/express-basics npm install npm run dev -
Task API (Day 2b):
cd day-2-structured-api/task-api npm install npm run devCRUD curl examples: day-2-structured-api/task-api/README.md.
-
MongoDB Task API (Day 3):
cd day-3-persistence/task-mongo cp .env.example .env # set MONGODB_URI npm install npm run dev # http://localhost:4001
Setup, env vars, and curl examples: day-3-persistence/task-mongo/README.md.
-
Interactive learning (Days 1β4 modules):
cd interactive-learning npm install npm run dev # http://localhost:6700
-
Auth API + UI (Day 4): see Day 4: Authentication & security below for two-terminal setup and day-4-auth-and-security/auth/README.md for demo users.
- Foundation for understanding Express basics
- Simple route handling
- Request/response fundamentals
- Your entry point into Express after understanding Node.js HTTP basics
Beginner & Intermediate Level
A complete beginner-to-intermediate project with proper structure:
- app.js: Main Express application file
- userController.js: Handles user-related HTTP requests
- userRoutes.js: Defines API routes for user operations
- data.js: Sample user data for testing
Features:
- CRUD operations for user management
- Role-based user structure (admin, manager, user)
- Separation of routes from controllers
- Search and filter functionality
- Error handling examples
- Input validation
- RESTful API design
This project shows how to organize Express applications properly and is your bridge between basic Express understanding and advanced architecture patterns.
Advanced Level
A production-ready Express application demonstrating professional architecture and best practices.
Architecture: Complete MVC Pattern with separation of concerns
- Controllers (
src/controllers/): Handle HTTP requests with validation - Services (
src/services/): Contain business logic - Repositories (
src/repositories/): Manage data persistence - Routes (
src/routes/): Define API endpoints
- β Create tasks with priority levels (1-5)
- β Update existing tasks
- β Delete tasks
- β Retrieve all tasks
- β Get individual task by ID
- β Input validation and error handling
- β Duplicate title prevention
- β HTTP request logging with Morgan
- β CORS support
POST /tasks - Create a new task
GET /tasks - Get all tasks
GET /tasks/:id - Get task by ID
PUT /tasks/:id - Update a task
DELETE /tasks/:id - Delete a task
Create Task:
POST /tasks
Content-Type: application/json
{
"title": "Learn Express Middleware",
"priority": 3,
"deadline": "2026-12-31"
}Task Response:
{
"title": "Learn Express Middleware",
"priority": 3,
"deadline": "2026-12-31T00:00:00.000Z"
}Day 3 β Persistence
Same REST endpoints as task-api, with tasks stored in MongoDB (data survives restart). Default port 4001 so it can run beside the in-memory API on 4000. Details: day-3-persistence/task-mongo/README.md.
Coming from native Node.js HTTP servers, Express provides:
- β Built-in routing system instead of manual if/else chains
- β Automatic header management
- β Easy middleware integration
- β Clean, readable, scalable code
- β Rich ecosystem of ready-to-use middleware
| Aspect | Node.js HTTP | Express |
|---|---|---|
| Routing | Manual if/else logic | Built-in Router with methods |
| Middleware | Must build from scratch | Thousands available |
| Body Parsing | Manual implementation | express.json() |
| Error Handling | Verbose try/catch | Centralized error handlers |
| Code Length | Lots of boilerplate | Concise & readable |
| Scalability | Gets messy fast | Scales elegantly |
| Learning Curve | Steep | Gentle progression |
| Production Ready | Possible but complex | Yes, out of the box |
Path: interactive-learning/
One Vite app with modules for architecture, request lifecycle, CRUD, validation, errors, middleware, and full auth (JWT, RBAC, end-to-end);
- Architecture β layers from route to repository (and database)
- Request lifecycle β step through a request/response
- CRUD, validation, errors, middleware β production-shaped API patterns
- Auth β authentication vs authorization, JWT, protected routes, RBAC
cd interactive-learning
npm install
npm run devSee interactive-learning/README.md for details.
Runnable API + UI under day-4-auth-and-security/auth/, plus interactive auth modules in interactive-learning/.
The interactive-learning/ module teaches core security topics through interactive visualizations:
- Authentication Fundamentals - User login, JWT tokens, password hashing
- Authorization & Permissions - Role-based access control (RBAC), middleware guards
- API Security - CORS, rate limiting, input sanitization
- Password Management - Hashing, salting, bcrypt patterns
- JWT Implementation - Token generation, validation, expiration
- Security Best Practices - HTTPS, secure headers, OWASP guidelines
cd interactive-learning
npm install
npm run dev
# Opens http://localhost:6700Hands-on apps that match the interactive module:
# Terminal 1 β Auth API (port 4000)
cd day-4-auth-and-security/auth/task-with-auth && npm install && npm run dev
# Terminal 2 β Auth UI (port 5173)
cd day-4-auth-and-security/auth/task-with-auth-ui && npm install && npm run devDemo logins, endpoints, and environment variables: day-4-auth-and-security/auth/README.md.
See interactive-learning/README.md for installation and learning guides.
To understand what Express simplifies, here's how to build a basic HTTP server with native Node.js (without any framework):
- Manual Routing: Every route requires if/else statements
- Header Management: You manually set headers for each response
- Body Parsing: Parsing request bodies requires manual stream handling
- Middleware: Creating reusable middleware is complex
- Scalability: Code becomes unwieldy as the application grows
- Error Handling: No centralized error handling mechanism
- Development Time: Much more boilerplate code for simple tasks
See day-1-http-and-express/expressapp.js for how Express simplifies all of this with just a few lines:
Result:
- No manual routing logic
- Automatic header management
- Built-in JSON parsing
- Much cleaner and more maintainable
This is why day-1-http-and-express/nodeserver.js existsβto remind you of these challenges and help you appreciate the elegance that Express brings to Node.js development.
The task management project demonstrates the MVC pattern:
- Controllers (
taskControllers.js): Handle HTTP requests, validation, and responses - Services (
taskServices.js): Contain core business logic - Repositories (
taskRepository.js): Manage data access and persistence
- Morgan: HTTP request logging
- CORS: Cross-origin resource sharing
- Express JSON: Built-in JSON parser
| Concept | Implementation |
|---|---|
| Routing | Express Router in task routes |
| Controllers | Request/response handling |
| Services | Business logic separation |
| Repositories | Data access patterns |
| Validation | Input validation in controllers |
| Error Handling | Try-catch and status codes |
| Middleware | Morgan and CORS integration |
| REST API | Full CRUD implementation |
import express from "express";
import taskRoutes from "./src/routes/taskRoutes.js";
const app = express();
app.use(express.json());
app.use("/tasks", taskRoutes);
app.listen(3000, () => {
console.log("Server running on port 3000");
});const createTaskService = (title, priority, deadline) => {
deadline = new Date(deadline);
return createTaskRepository(title, priority, deadline);
};export const createTaskController = async (req, res) => {
try {
const { title, priority, deadline } = req.body;
if (!title || !priority || !deadline) {
return res.status(400).json({
message: "Title, priority and deadline are required."
});
}
const result = await createTaskService(title, priority, deadline);
return res.status(201).json(result);
} catch (error) {
return res.status(500).json({
message: "An error occurred while creating the task."
});
}
};- express - Web framework
- morgan - HTTP request logging
- cors - Cross-origin resource sharing
- ES6 modules enabled (
"type": "module"in package.json) - Node.js native module support
- Start with Day 1:
day-1-http-and-express/nodeserver.jsthenexpressapp.js - Explore express-basics:
app.js,userRoutes.js,userController.js, anddata.js - Progress to task-api: Full layered MVC (repository β service β controller)
- Build incrementally: Each day adds layers on the same request path
- Understand layers: Study repository β service β controller flow
- Experiment: Modify code and see how changes affect behavior
- Use logging: Morgan on task-api and task-mongo
- Reference Day 1: When stuck, compare with
nodeserver.jsto appreciate Express
β Separation of concerns (layers: controller, service, repository)
β Input validation at controller level
β Error handling with appropriate HTTP status codes
β RESTful endpoint design
β Middleware integration
β Async/await for asynchronous operations
β Environment-aware configuration
git log --onelinegit config user.name
git config user.email# Using curl
curl -X GET http://localhost:4000/tasks
# Or use Postman/Insomnia for better UI- Express.js Official Documentation
- Node.js Documentation
- RESTful API Best Practices
- JavaScript Async/Await Guide
This is a learning repository. Feel free to:
- Add new features
- Improve existing code
- Create additional examples
- Suggest improvements
ISC
Created for Express.js learners by the community
Happy Learning! π
Start with the beginner examples and progressively work your way through the advanced task management API. Each step builds upon the previous one to help you master Express.js development.