NestJS at a Glance

NestJS in One Page (covered fully in Section 3.15)

NestJS 79,377 answers the complaint Express 24,430 is proudest of: it tells you how to structure an application. The shape is borrowed from Angular 42,088 — TypeScript classes, decorators for metadata, a dependency injection container — and underneath it is still Express, because NestFactory.create uses @nestjs/platform-express unless you hand it the Fastify 314,116 adapter. Three roles cover most of a Nest codebase: a provider holds logic, a controller maps routes onto methods, and a module declares which of them belong together.

A Nest module, controller and provider (app.ts)TypeScript
@Injectable()
export class BooksService {
  list() { return books; }
}
@Controller('books')                          // every route below is prefixed /books
export class BooksController {
  constructor(private readonly service: BooksService) {}   // injected by type
  @Get()
  list() { return { data: this.service.list() }; }         // returned, not res.json()
}
@Module({ controllers: [BooksController], providers: [BooksService] })
export class AppModule {}
Output
$ curl -s localhost:4365/books
{"data":[{"id":"bk_1","title":"Book number 1","authorId":"au_1","year":1950}, ...]}
$ curl -s localhost:4365/books/nope
{"message":"Cannot GET /books/nope","error":"Not Found","statusCode":404}

Notice what the controller does not do: it never touches res. A handler returns a value and Nest serializes it, which is what makes interceptors, exception filters and unit tests straightforward.

NestJS Version rebuilds the whole API in Nest: DTOs and validation pipes, guards, interceptors, exception filters, the Mongoose 243,355 module, OpenAPI from the decorators, and testing.