NestJS From Zero
NestJS is what you reach for when an Express app grows up and the "middleware soup" starts to hurt. It's an opinionated, TypeScript-first framework that brings a real architecture to Node backends — borrowed, openly, from Angular: modules, controllers, providers, decorators, and a proper dependency-injection container. Under the hood it runs on Express (or Fastify) but adds the structure and conventions that keep large teams and large codebases sane. If you like strong typing and a place for everything, Nest is the Node framework for you.
The mental model is three roles wired by DI. A controller handles HTTP — its methods are decorated with
@Get()/@Post() and map requests to responses. A provider (usually a @Injectable() service) holds
business logic and is injected into controllers (and other providers) by Nest's container — you never
new your dependencies. A module (@Module()) groups related controllers and providers and declares
what it exposes, so the app is a tree of modules. Hold "controllers handle HTTP, providers hold logic, DI
wires them, modules group them," and Nest's decorators stop looking like magic and become a clear structure.
📝 This teaches the framework — it assumes TypeScript: types, classes, decorators, generics (TypeScript From Zero) on top of JavaScript/Node. It's most useful read after Express (which it runs on and improves upon); the DI + decorator style echoes Spring Boot and ASP.NET Core. Nest runs on Node, so examples are shown with the commands to run them.
How to read this
Read in order — it grows one service (a small tasks API) from a single controller to a structured, tested, deployable REST API. Phases carry difficulty badges.
The phases
Part 1 — The building blocks (🟢 → 🟡)
- What NestJS Is & Your First App 🟢 — the architecture, the CLI, and a running app.
- Controllers & Routing 🟡 —
@Controller, route decorators, params, and responses. - Providers & Dependency Injection 🟡 —
@Injectableservices and how Nest injects them. - Modules 🟡 —
@Module, imports/exports, and organizing the app.
Part 2 — A real API (🟡 → 🔴)
5. DTOs, Validation & Pipes 🔴 — typed request bodies, class-validator, and the ValidationPipe.
6. Building a REST API 🟡 — a full resource: controller + service + DTOs.
7. Guards, Interceptors & Middleware 🔴 — auth guards, the request pipeline, and cross-cutting logic.
Part 3 — Ship it (🟡 → 🟢) 8. Testing & Production 🟡 — unit tests with the DI test module, e2e tests, and deployment. 9. Where to Go Next 🟢 — Nest vs Express/Fastify, TypeORM/Prisma, microservices, and what to build.
The throughline: controllers handle HTTP, providers hold logic, dependency injection wires them, and modules group them. That structure is why Nest scales where bare Express sprawls.