This document provides a comprehensive overview of the 30+ sample applications included in the NestJS repository. Each sample demonstrates specific features, integration patterns, or architectural approaches. The samples serve as practical references for implementing NestJS functionality and are organized by category to help developers find relevant examples quickly.
For information about the core framework packages, see Core Package Ecosystem. For testing infrastructure used in these samples, see Testing Infrastructure.
The NestJS repository contains sample applications located in the sample/ directory. Each sample is a standalone NestJS application with its own package.json, demonstrating specific functionality or integration patterns. All samples share the same NestJS core version (11.1.28) and follow consistent project structures.
Sources: sample/01-cats-app/package.json1-71 sample/07-sequelize/package.json1-74 sample/11-swagger/package.json1-54
These samples demonstrate fundamental NestJS concepts including controllers, services, modules, and dependency injection.
| Sample Directory | Primary Focus | Key Dependencies | Description |
|---|---|---|---|
01-cats-app | REST API Fundamentals | class-validator, class-transformer | Basic CRUD operations with DTOs, validation, and E2E tests |
25-dynamic-modules | Dynamic Module Pattern | dotenv | Configuration module using dynamic module registration |
The 01-cats-app sample serves as the canonical "hello world" for NestJS, demonstrating the basic request/response cycle with controllers and services. It includes comprehensive E2E tests using Jest and supertest.
Sources: sample/01-cats-app/package.json1-71 sample/25-dynamic-modules/package.json1-67
Database integration samples demonstrate ORM/ODM patterns with various database systems.
| Sample Directory | ORM/ODM | Database | Key Package | Version |
|---|---|---|---|---|
05-sql-typeorm | TypeORM | MySQL | @nestjs/typeorm | 11.0.3 |
07-sequelize | Sequelize | MySQL | @nestjs/sequelize | 11.0.1 |
13-mongo-typeorm | TypeORM | MongoDB | @nestjs/typeorm | 11.0.3 |
06-mongoose | Mongoose | MongoDB | @nestjs/mongoose | 11.0.4 |
14-mongoose-base | Mongoose | MongoDB | mongoose | 9.7.4 |
22-graphql-prisma | Prisma | SQLite | @prisma/client | 7.8.0 |
The TypeORM sample demonstrates SQL database integration with MySQL. Key dependencies include typeorm (1.1.0), mysql2 (3.23.1), and @nestjs/typeorm (11.0.3). This sample shows entity definition, repository pattern usage, and database connection configuration.
Sources: sample/05-sql-typeorm/package.json21-30
The Sequelize sample provides an alternative ORM approach for SQL databases. It uses sequelize (6.37.8), sequelize-typescript (2.1.6), and @nestjs/sequelize (11.0.1). This sample demonstrates model definition with decorators and transaction handling.
Sources: sample/07-sequelize/package.json21-32
Demonstrates Mongoose ODM integration. It utilizes @nestjs/mongoose (11.0.4) and mongoose (9.7.4). This sample shows how to define schemas and use the MongooseModule to inject models into services.
Sources: sample/06-mongoose/package.json21-26
A modern implementation showing GraphQL integration with Prisma. It uses @prisma/client (7.8.0) and @prisma/adapter-better-sqlite3 (7.8.0). This sample demonstrates the code-first GraphQL approach combined with Prisma's type-safe database client.
Sources: sample/22-graphql-prisma/package.json23-30
These samples demonstrate API documentation generation and request/response validation patterns.
| Sample Directory | Focus | Key Package | Additional Tools |
|---|---|---|---|
11-swagger | OpenAPI Documentation | @nestjs/swagger (11.4.6) | class-validator, class-transformer |
21-serializer | Response Transformation | class-transformer (0.5.1) | N/A |
The Swagger sample demonstrates automatic API documentation generation using the @nestjs/swagger package. It shows how decorators generate OpenAPI specifications. The sample includes DTO validation with class-validator (0.15.1) and response transformation with class-transformer (0.5.1).
Sources: sample/11-swagger/package.json21-30
Real-time communication samples demonstrate WebSocket implementations and Server-Sent Events.
Demonstrates unidirectional real-time streaming from server to client using the @Sse() decorator. This is a lightweight alternative to WebSockets for scenarios where only server-to-client communication is needed.
Sources: sample/28-sse/package.json1-53
Microservices samples demonstrate distributed system patterns with various transport layers.
| Sample Directory | Transport Layer | Key Package | Protocol |
|---|---|---|---|
03-microservices | TCP/Redis/MQTT/Kafka/NATS/RabbitMQ | @nestjs/microservices (11.1.28) | Message patterns |
04-grpc | gRPC | @grpc/grpc-js (1.14.4) | Protocol Buffers |
Implements gRPC microservices using @grpc/grpc-js (1.14.4) and @grpc/reflection (1.0.4). Demonstrates protocol buffer definition and unary/streaming RPC methods.
Sources: sample/04-grpc/package.json21-32
GraphQL samples demonstrate different approaches to GraphQL API development, including federated architectures and alternative engines.
Uses SDL (Schema Definition Language) files. It relies on @nestjs/apollo (13.4.2) and @nestjs/graphql (13.4.2). This sample demonstrates how to generate TypeScript definitions from SDL and implement resolvers.
Sources: sample/12-graphql-schema-first/package.json21-35
Demonstrates GraphQL integration using Mercurius, a high-performance GraphQL adapter for Fastify. It uses @nestjs/mercurius (13.4.2) and @nestjs/platform-fastify (11.1.28).
Sources: sample/33-graphql-mercurius/package.json21-31
Feature samples demonstrate specific NestJS capabilities and common integration patterns.
| Sample Directory | Feature | Key Package(s) | Description |
|---|---|---|---|
19-auth-jwt | Authentication | @nestjs/jwt, @nestjs/passport | JWT authentication with Passport strategies |
20-cache | Caching | @nestjs/cache-manager | Multi-store cache integration |
26-queues | Background Jobs | @nestjs/bull (11.0.4) | Redis-backed job queues using Bull (4.16.5) |
27-scheduling | Task Scheduling | @nestjs/schedule | Cron-based task scheduling |
29-file-upload | File Upload | @types/multer | Multipart form data handling |
Demonstrates Redis-backed job queues using Bull (4.16.5) via @nestjs/bull (11.0.4). Shows queue producers and consumers with job processors.
Sources: sample/26-queues/package.json21-30
Platform adapter samples demonstrate NestJS's ability to work with different HTTP server implementations and MVC patterns.
Server-side rendering using Fastify platform with Handlebars templates. Key packages:
@nestjs/platform-fastify (11.1.28)@fastify/view (12.0.0)@fastify/static (9.3.0)handlebars (4.7.9)Sources: sample/17-mvc-fastify/package.json21-30
Demonstrates custom Webpack configuration for NestJS applications. It includes webpack-hmr.config.js for Hot Module Replacement and uses start-server-webpack-plugin (2.2.5).
Sources: sample/08-webpack/package.json22-37
All samples include standard npm scripts for the development lifecycle:
build: Compiles TypeScript using nest build sample/06-mongoose/package.json8start:dev: Runs with hot reload using --watch sample/06-mongoose/package.json11test: Runs Jest unit tests sample/06-mongoose/package.json15lint: Runs ESLint with automatic fixes sample/06-mongoose/package.json14All samples maintain version consistency with the core framework (v11.1.28):
| Package Type | Version | Consistency |
|---|---|---|
NestJS Core (@nestjs/core, @nestjs/common) | 11.1.28 | All samples |
Platform Adapters (@nestjs/platform-*) | 11.1.28 | All samples |
| TypeScript | 5.9.3 | All samples |
| Jest | 30.4.2 | All samples |
Sources: sample/06-mongoose/package.json22-25 sample/07-sequelize/package.json22-24 sample/04-grpc/package.json24-27
Each sample follows a consistent directory structure as seen in the source tree:
Sources: sample/01-cats-app/package.json1-71 sample/07-sequelize/package.json1-74
Refresh this wiki