Skip to content
Tutorials Center
My learning

Topics

Express.js Tutorial

Learn Express.js step by step: 43 lessons in 12 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Express? Learn what Express.js is, what it adds on top of Node's http module, how Express 5 differs from 4, and how this course runs a mini Express right in your browser.
  2. 2 Express vs Fastify, Koa, NestJS and Hapi Compare Express with Fastify, Koa, NestJS and Hapi: design ideas, speed, ecosystem, enterprise and microservice fit, and a clear guide to choosing the right Node.js framework.
  3. 3 Your First Express App Create your first Express 5 app: install with npm, write a hello-world route, start it with app.listen, restart on changes, and try the same flow on a mini Express.
  4. 4 Inside Express: Building a Mini Express See how Express works inside by reading a 60-line mini framework: a layer stack, path matching, next(), error handlers and the res helpers used in every lesson.
  5. 5 Project Setup and Structure Set up an Express project the clean way: package.json with ES modules, routes, controllers and services folders, config from environment variables, and app vs server.
  6. 6 The Express Generator and Project Scaffolding See what npx express-generator creates, read the generated app.js, bin/www and folders, then modernize it for Express 5 and ES modules or skip it with a manual setup.

Routing

  1. 7 Routing Basics Learn Express routing: app.get, post, put, patch and delete, app.all, how route order decides which handler runs, and how 404 fallthrough works, with runnable demos.
  2. 8 Route Parameters and Query Strings Read data from the URL in Express: req.params, req.query, parsing numbers safely, and the Express 5 path syntax changes for wildcards and optional parameters.
  3. 9 Modular Routing with express.Router Split an Express app into small routers: mount them under a prefix, share parameters with mergeParams, add router-level middleware and chain verbs with app.route.
  4. 10 Application Settings, Sub-Apps and Mount Events Learn Express application settings (app.set, app.get, enable, disable, etag, case sensitive routing, json spaces, trust proxy) and how mounted sub-apps inherit them.

Middleware

  1. 11 How Middleware Works Understand Express middleware: the (req, res, next) signature, why order matters, path-scoped app.use, short-circuiting and how errors skip the normal chain.
  2. 12 Built-in Middleware Learn the middleware that ships with Express: express.json, urlencoded, text, raw and static, their limits, and why req.body is undefined in Express 5 without a parser.
  3. 13 Common Third-Party Middleware A tour of the middleware most Express apps install: morgan for logs, cors, helmet for security headers, compression and cookie-parser, with when to use each.
  4. 14 Writing Your Own Middleware Write your own Express middleware: a request ID, a response timer, an auth guard and configurable middleware factories, with async handling and testing tips.

Request and Response

  1. 15 The Request Object Tour the Express request object: req.method, path, query, headers, req.get, ip, hostname, protocol, content negotiation with req.accepts and the trust proxy setting.
  2. 16 The Response Object Learn the Express response object: res.send, res.json, res.status, sendStatus, redirect, headers and type, chaining, and the headers-already-sent error.
  3. 17 Cookies and Headers Set and read cookies in Express with res.cookie and cookie-parser, choose httpOnly, secure and sameSite, sign cookies, and use Cache-Control and ETag headers.
  4. 18 Static Files, Downloads and Streaming Serve static files with express.static, send single files with res.sendFile and res.download, stream big responses, and see how range requests and dotfiles work.

Views and Templating

  1. 19 Template Engines and Server-Side Rendering Render HTML pages on the server with Express: app.set views and view engine, res.render, locals, layouts, and a comparison of EJS, Pug and Handlebars.
  2. 20 Forms, Redirects and Flash Messages Handle HTML forms in Express: parse urlencoded bodies, validate, use the POST-Redirect-GET pattern, override methods, and show flash messages from a session.

Building REST APIs

  1. 21 Designing a REST API in Express Design a clean REST API with Express: resources and verbs, status codes, pagination, filtering, sorting, versioning and one consistent JSON shape.
  2. 22 Controllers and Services Split an Express API into routes, controllers and services, write async handlers, and learn how Express 5 forwards rejected promises to your error handler.
  3. 23 Validating Input Validate Express request bodies, params and queries: manual checks, Zod and Joi schemas, express-validator, reusable validation middleware and 422 responses.

Errors and Robustness

  1. 24 Error Handling Handle errors in Express the right way: four-argument error middleware, a 404 handler, async errors in Express 5 vs 4, custom error classes and safe responses.
  2. 25 Logging and Debugging Log requests in Express with morgan and pino-http, write structured JSON logs, add correlation IDs, and debug internals with DEBUG=express:*.

Security and Auth

  1. 26 Sessions and Login Build login with sessions in Express: session cookies, express-session and Redis stores, password hashing with argon2 and bcrypt, logout and CSRF basics.
  2. 27 JWT Authentication and Authorization Use JSON Web Tokens in Express: access and refresh tokens, the Bearer header, jsonwebtoken, role-based guards and the pitfalls of storing tokens in the browser.
  3. 28 Security Best Practices Harden an Express app: helmet headers, CORS allow lists, rate limiting, input handling, injection, XSS, CSRF, trust proxy, HTTPS and dependency audits.

Data and Files

  1. 29 Databases with Express Connect Express to a database: PostgreSQL and MySQL drivers, MongoDB with Mongoose, Prisma, connection pools and the repository pattern, with a SQLite demo.
  2. 30 File Uploads Handle file uploads in Express with multer: multipart forms, size and type limits, disk and S3 storage, safe file names, and a runnable multipart parser.
  3. 31 Real-Time Features: SSE and WebSockets Push live data from Express with Server-Sent Events, and learn when ws or socket.io is the better choice, with runnable SSE and broadcast examples.

Quality and Operations

  1. 32 Testing Express Apps Test Express apps: separate app from listen, use supertest and node:test, mock services, and check middleware and errors, with runnable fetch-based tests.
  2. 33 Performance and Caching Speed up Express: compression, ETag and Cache-Control, response caching, keeping the event loop free, clustering and keep-alive, with runnable demos.
  3. 34 Deployment and Production Take an Express app to production: NODE_ENV, environment config, nginx as a reverse proxy, PM2, Docker, health checks, graceful shutdown and an Express 5 checklist.
  4. 35 ESLint, Prettier and the Test Pyramid for Express Set up ESLint and Prettier for an Express project, learn what the test pyramid means for APIs, run unit and integration tests, and try routes with curl, Postman or Insomnia.

Projects

  1. 36 Project: Todo REST API Build a complete Todo REST API: CRUD routes, input validation, a central error handler and tests. Real Express code is read-only; a runnable stand-in shows it work.
  2. 37 Project: Authenticated Notes API Build a Notes API with registration, login, signed tokens, per-user data and authorization checks. Real Express code is read-only; a runnable stand-in proves it works.
  3. 38 Project: Server-Rendered Blog Build a server-rendered blog: routes, HTML templates with escaping, pagination, a post form, redirect after POST and flash messages. Runnable stand-in renderer included.
  4. 39 Project: URL Shortener Service Build a URL shortener: create, redirect and stats endpoints, URL validation, a rate limiter and a lookup cache. Real Express code is read-only; a runnable stand-in is included.
  5. 40 Project: File Upload and Download Service Build a file service: upload size limits, safe file names, metadata, streaming downloads with correct headers. Real multer code is read-only; a runnable stand-in is included.

Practice and Review

  1. 41 Exercises with Solutions Practice Express.js with five graded exercises on routing, middleware, validation, error handling and API-key auth. Each has a hint and a runnable solution.
  2. 42 Express Interview Questions Prepare for Express.js interviews with short answers on middleware, next(), routing, error handling, Express 4 vs 5, security and scaling, plus runnable demos.
  3. 43 Express Cheat Sheet A quick Express 5 reference: routing, middleware order, request and response helpers, error handling, security and deployment snippets, with two runnable demos.