NestJS modules and controllers
Framework lane: NestJS 11.x candidate, TypeScript legacy decorators and emitDecoratorMetadata, compatible reflect-metadata and RxJS. Exact supported patch, dependency lock, advisory review and execution are NOT RUN. The framework code is a static candidate; do not install dependencies or expose a server automatically. The local companion uses Node.js 22.16.0 and requires no third-party packages. A decorator such as @Controller attaches framework metadata; a TypeScript annotation describes a compile-time contract. The full TypeScript chapter follows this introduction. Use a reviewed Nest TypeScript project, not node directly on the .ts file.
Framework example — staged
import { Controller, Get, Injectable, Module } from '@nestjs/common';@Injectable()class CatalogService { list() { return [{id:'p1', title:'Notebook'}]; }}@Controller('catalog')class CatalogController { constructor(private readonly service: CatalogService) {} @Get() list() { return this.service.list(); }}@Module({controllers:[CatalogController],providers:[CatalogService]})export class CatalogModule {}Expected behavior (not observed): Partial TypeScript module for an approved Nest 11.x app; when registered and initialized, GET /catalog should return a JSON array containing p1.
How it works
The @Module decorator declares module metadata. @Controller sets a route prefix and @Get selects a method and optional path. The default HTTP adapter is Express in the standard Nest setup; alternative adapters exist. Nest uses TypeScript decorators and metadata in typical projects; configure the reviewed compiler before attempting these examples. An exported provider may be used by a module that imports its owning module.
Practice the underlying idea without dependencies
class CatalogService { list(){return [{id:'p1',title:'Notebook'}];} }class CatalogController { constructor(service){this.service=service;} list(){return this.service.list();} }console.log(JSON.stringify(new CatalogController(new CatalogService()).list()));Run node main.mjs in a disposable directory. Expected output:
[{"id":"p1","title":"Notebook"}]This tests the illustrated JavaScript behavior only, not the framework.
Common mistake
A plain class is not automatically an HTTP controller. Module registration, decorators, compiler metadata and the adapter are required. The local example exercises ordinary class composition only.
Apply it yourself
Sketch a catalog module and a shipping module, and identify the provider that must be exported if shipping needs catalog data.
Further reading
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
NestJS modules and controllers — knowledge check
Apply the lesson’s contracts and identify common boundary mistakes.
What declares the controllers and providers of a Nest module?
Where should reusable catalog logic live?
What must another module do to use a deliberately exported provider?