Learn Express

Minimal, unopinionated web framework for Node.js

24 lessons · 5 hours · 4 levels · covers Express 5

Express is the most widely used web framework for Node.js: a thin layer over the http module that adds routing, a middleware pipeline and convenient request and response helpers. It is used to build JSON APIs, server-rendered sites and backend services, and its middleware model shaped most of the Node web ecosystem. Express 5 adds native async error handling and a safer routing syntax.

Before you start

Express builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics8 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms16 lessons · 3 hours in total
3. AdvancedThe less common features, performance and trade-offs21 lessons · 4 hours in total
4. ExpertInternals and the edge cases experts know24 lessons · 5 hours in total

The Express tree

ExpressWhat Express isWhat Express isYour first Express appYour first ExpressappRouting: methods and pathsRouting: methodsand pathsRoute parameters, wildcards and query stringsRoute parameters,wildcards and quer…The request objectThe request objectSending responsesSending responsesParsing JSON and form bodiesParsing JSON andform bodiesServing static filesServing static filesMiddleware and next()Middleware andnext()Routers and project structureRouters and projectstructureError handling and async errorsError handling andasync errorsValidating inputValidating inputDesigning a REST APIDesigning a REST APICORS for browser clientsCORS for browserclientsAuthentication: sessions and JWTsAuthentication:sessions and JWTsTesting Express apps with supertestTesting Express appswith supertestnpm and package.jsonnpm andpackage.jsonWorking with JSONWorking with JSONPaths, URLs and the os modulePaths, URLs and theos moduleError handling in Node applicationsError handling inNode applicationsEnvironment variables and .env filesEnvironmentvariables and .env f…Testing with node:testTesting withnode:testStreams: reading and writing in chunksStreams: reading andwriting in chunksBuilding an HTTP server with node:httpBuilding an HTTPserver with node:http
Essentials and Practical shown (16 of 24 lessons); the full list is below. Click a lesson to read it.

All 24 lessons, in order

Getting started

  1. What Express is · Essentials · 6 min

    Express is a minimal web framework over Node's http module: routing, middleware and request/response helpers.

  2. Your first Express app · Essentials · 8 min

    Create an app, register a route, start listening on a port, and understand what each line does.

  3. Serving static files · Essentials · 9 min

    Serve images, CSS, JS and HTML from a folder with express.static, with mount paths, caching and safe defaults.

Routing, requests and responses

  1. Routing: methods and paths · Essentials · 10 min

    Map HTTP methods and URL paths to handlers with app.get/post/put/delete, app.all and app.route.

  2. Route parameters, wildcards and query strings · Essentials · 12 min

    Capture URL segments with :params, optional parts with braces, wildcards with *name, and read req.query.

  3. The request object · Essentials · 10 min

    Read headers, the client IP, protocol, hostname, cookies and content type from Express's req object.

  4. Sending responses · Essentials · 11 min

    Send JSON, text, files, redirects and status codes with res.json, res.send, res.status, res.sendFile and friends.

  5. Parsing JSON and form bodies · Essentials · 10 min

    Parse request bodies with express.json() and express.urlencoded(), set size limits, and handle malformed input.

Middleware, routers and errors

  1. Middleware and next() · Practical · 13 min

    Understand middleware functions (req, res, next), how app.use mounts them, and why order matters.

  2. Routers and project structure · Practical · 12 min

    Split an app into express.Router modules, mount them under prefixes, and organise files by feature.

  3. Error handling and async errors · Practical · 14 min

    Write 404 and error-handling middleware, rely on Express 5 forwarding async rejections, and map errors to status codes.

Building real APIs

  1. Validating input · Practical · 13 min

    Validate and coerce params, query and body with a schema library such as Zod, and return clear 400 errors.

  2. Designing a REST API · Practical · 14 min

    Model resources with nouns and HTTP methods, use correct status codes, paginate, and keep error formats consistent.

  3. CORS for browser clients · Practical · 11 min

    Understand the same-origin policy, preflight requests, and configure the cors middleware with explicit origins.

  4. Authentication: sessions and JWTs · Practical · 16 min

    Compare cookie sessions and JWT bearer tokens, hash passwords properly, and protect routes with auth middleware.

  5. Testing Express apps with supertest · Practical · 13 min

    Test routes end to end in-process with supertest and node:test: status codes, bodies, headers and auth.

Production readiness

  1. Security hardening: helmet and rate limiting · Advanced · 15 min

    Harden an Express app with helmet's security headers, rate limiting, body limits, safe cookies and up-to-date dependencies.

  2. Performance and HTTP caching · Advanced · 14 min

    Speed up Express apps with production mode, compression, ETags, Cache-Control, application caching and avoiding blocking work.

  3. Handling file uploads · Advanced · 13 min

    Accept multipart/form-data uploads with multer: limits, file filtering, disk vs memory storage, and streaming to object storage.

  4. Logging and observability · Advanced · 14 min

    Add structured request logs with request IDs, log errors once with context, expose health checks, and trace with OpenTelemetry.

  5. Deploying behind a proxy · Advanced · 15 min

    Run Express in production behind a load balancer: trust proxy, HTTPS, ports, process management and graceful shutdown.

Internals and Express 5

  1. Inside the router: layers and matching · Expert · 18 min

    How Express 5's router stores layers, matches paths, walks the stack with next(), and skips between normal and error handlers.

  2. Writing reusable middleware and libraries · Expert · 16 min

    Design configurable middleware factories that are composable, async-safe, typed and publishable.

  3. Migrating to Express 5: changes and edge cases · Expert · 18 min

    What changed from Express 4 to 5: path syntax, async errors, removed APIs, req.query/req.body behaviour and subtle defaults.