Architecture and Reference in Express.js

Architecture and Reference is the last chapter of the free Express.js tutorial. It organises, types and tests a full project, then builds the complete canteen API.

What each lesson covers:

  • Application Structure: Splitting app.js and server.js, a folder layout, a config module, registration order, graceful shutdown and tests with Supertest.
  • Express with TypeScript: Setup with tsx and tsc, typed routes, extending Request with req.user, runtime type guards and Zod, and building for production.
  • Capstone: The Complete Canteen API: One project with SQLite, hashed passwords, JWT login, roles, validation, central errors, tests, OpenAPI docs and graceful shutdown.
  • Express.js Cheat Sheet: Every important Express 5 API on one page, plus an Express 4 to 5 migration checklist and a starter project.

The labs can run your tests with node --test and type-check with npx tsc --noEmit, just like on your own computer.

Lessons in this section

  1. Application Structure

    Splitting app.js and server.js, a project folder layout, a central config module, registration order, startup errors and graceful shutdown, testing with node:test and Supertest, Express Generator, and keeping code healthy.

    • Split app.js and server.js
    • Organise routes, handlers, middleware and config
    • Register middleware in the right order
    • Handle startup errors and SIGTERM
  2. Express with TypeScript

    Setting up tsx and tsc, catching bugs with tsc --noEmit, typing params, bodies and responses, extending Request with req.user, runtime type guards and Zod, and building for production.

    • Set up an Express project with TypeScript
    • Find bugs with tsc --noEmit
    • Type params, bodies and responses
    • Add req.user with declare global
  3. Capstone: The Complete Canteen API

    One full project: SQLite tables, hashed passwords, JWT login, staff and student roles, validated orders with ownership checks, central errors, supertest tests, OpenAPI docs, health checks and graceful shutdown.

    • Combine every part of the course in one project
    • Store data in SQLite with safe queries
    • Protect routes with JWTs, roles and ownership
    • Handle every error in one place
  4. Express.js Cheat Sheet

    A one-page reference for Express 5: project setup, application settings, request and response methods, routing and Express 5 path syntax, routers, middleware, views, static files, sessions, files, REST status codes, errors, redirects, proxies, logging, security, registration order and an Express 4 to 5 migration checklist.