{"id":"6b09417e5ce40d447918f2cb","slug":"nestjs","title":"NestJS 11 in practice – modules, DI, validation, Mongoose, queues and hexagonal architecture","summary":"We move the pierogi shop's order API to NestJS 11 – modules and dependency injection, controllers and DTOs with class-validator, pipes, guards, interceptors and exception filters, Zod-validated configuration, Mongoose 9, ports and adapters, scheduled jobs and a BullMQ queue, plus tests with swapped dependencies.","servedLang":"en","availableLangs":["pl","en"],"topics":["nestjs","hexagonal-architecture","express"],"techs":["node","typescript"],"tags":["nestjs-11","dependency-injection","class-validator","mongoose","bullmq","scheduling","guards","interceptors","jest"],"level":"intermediate","kind":"tutorial","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":24,"stats":{"views":4,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T08:38:22.920Z","updatedAt":"2026-11-27T13:01:09.027Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"green","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"NestJS 11 step by step – modules, providers and DI, DTOs with class-validator, ValidationPipe, guards, interceptors, exception filters, @nestjs/config, Mongoose, ports and adapters, @nestjs/schedule, BullMQ and unit tests.","wordCount":4713,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Express gives you freedom, NestJS gives you conventions. As an API grows and several people work on it, freedom turns into ten different ways of doing the same thing. NestJS enforces modules, dependency injection (DI) and a clear request lifecycle, while Express 5 still runs underneath. In this tutorial we move the pierogi shop's order API from the "},{"type":"text","text":"Express tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/express"}}]},{"type":"text","text":" to NestJS 11 and arrange it so that the database and the queue are swappable adapters."}]},{"type":"callout","attrs":{"variant":"info","title":"In a nutshell"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A module groups controllers and providers","marks":[{"type":"bold"}]},{"type":"text","text":", and the DI container creates objects and injects them through constructors. You declare dependencies, Nest assembles the graph."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A request goes through a fixed pipeline","marks":[{"type":"bold"}]},{"type":"text","text":": middleware → guards → interceptors → pipes → controller → (interceptors) → exception filters. Each stage has one job."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Ports as abstract classes","marks":[{"type":"bold"}]},{"type":"text","text":" ("},{"type":"text","text":"OrdersRepository","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"KitchenTickets","marks":[{"type":"code"}]},{"type":"text","text":") double as DI tokens. The service depends on ports, while Mongo and BullMQ are plugged in with one line in the module – and swapped in tests."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"What you will build"},"content":[{"type":"paragraph","content":[{"type":"text","text":"pierogi-nest","marks":[{"type":"code"}]},{"type":"text","text":": the same order API as in Express ("},{"type":"text","text":"POST/GET /api/orders","marks":[{"type":"code"}]},{"type":"text","text":", a status change protected by the kitchen key), but with MongoDB via Mongoose 9, a BullMQ queue that \"prints\" a kitchen ticket, a nightly cleanup of cancelled orders ("},{"type":"text","text":"@Cron","marks":[{"type":"code"}]},{"type":"text","text":"), a global rate limit and service tests without a database or Redis. Download the code (26 files) as a ZIP; "},{"type":"text","text":"docker compose up -d","marks":[{"type":"code"}]},{"type":"text","text":" starts MongoDB and Redis, "},{"type":"text","text":"npm run start:dev","marks":[{"type":"code"}]},{"type":"text","text":" starts the app."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Prerequisites:","marks":[{"type":"bold"}]},{"type":"text","text":" Node.js 22+ (24 recommended), Docker (for MongoDB and Redis), TypeScript with decorators at the level of \"I have seen "},{"type":"text","text":"@Something()","marks":[{"type":"code"}]},{"type":"text","text":" above a class\". Reading the "},{"type":"text","text":"Express tutorial","marks":[{"type":"link","attrs":{"href":"/en/articles/express"}}]},{"type":"text","text":" helps – comparing the two approaches is instructive."}]},{"type":"stats","attrs":{"items":[{"value":"11","label":"NestJS version","hint":"Express 5 underneath"},{"value":"2","label":"ports","hint":"order repository and kitchen tickets"},{"value":"6","label":"request pipeline stages","hint":"middleware, guard, interceptor, pipe, handler, filter"},{"value":"26","label":"files in the ZIP","hint":"with docker-compose and tests"}]}},{"type":"callout","attrs":{"variant":"info","title":"NestJS 11 or 12?"},"content":[{"type":"paragraph","content":[{"type":"text","text":"NestJS 12 shipped in August 2026 and its packages are ES modules. This tutorial sticks to the 11.x line – tagged "},{"type":"text","text":"legacy","marks":[{"type":"code"}]},{"type":"text","text":" on npm, but still patched regularly and used by most existing projects (this portal runs on it too). Modules, DI, decorators and the request lifecycle look the same in both versions; moving to 12 mostly changes module and tooling configuration – check the official migration guide."}]}]},{"type":"heading","attrs":{"level":2,"id":"step-1-the-project-and-local-infrastructure"},"content":[{"type":"text","text":"Step 1. The project and local infrastructure"}]},{"type":"paragraph","content":[{"type":"text","text":"You can scaffold the skeleton with "},{"type":"text","text":"npx @nestjs/cli@11 new pierogi-nest","marks":[{"type":"code"}]},{"type":"text","text":", but below is a complete, trimmed-down configuration – without ESLint and Prettier, to keep the focus on NestJS."}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"npm install\ncp .env.example .env\ndocker compose up -d      # MongoDB 8 + Redis 8\nnpm run start:dev"}]},{"type":"codeGroup","attrs":{"title":"Project configuration"},"content":[{"type":"codeBlock","attrs":{"language":"json","filename":"package.json"},"content":[{"type":"text","text":"{\n  \"name\": \"pierogi-nest\",\n  \"version\": \"1.0.0\",\n  \"private\": true,\n  \"scripts\": {\n    \"build\": \"nest build\",\n    \"start\": \"nest start\",\n    \"start:dev\": \"nest start --watch\",\n    \"start:prod\": \"node dist/main\",\n    \"typecheck\": \"tsc --noEmit\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {\n    \"@nestjs/bullmq\": \"^11.0.5\",\n    \"@nestjs/common\": \"^11.2.12\",\n    \"@nestjs/config\": \"^4.0.4\",\n    \"@nestjs/core\": \"^11.2.12\",\n    \"@nestjs/mongoose\": \"^11.0.4\",\n    \"@nestjs/platform-express\": \"^11.2.12\",\n    \"@nestjs/schedule\": \"^6.1.3\",\n    \"@nestjs/throttler\": \"^6.8.0\",\n    \"bullmq\": \"^6.7.10\",\n    \"class-transformer\": \"^0.5.1\",\n    \"class-validator\": \"^0.15.1\",\n    \"helmet\": \"^8.3.0\",\n    \"ioredis\": \"^6.1.0\",\n    \"mongoose\": \"^9.13.1\",\n    \"reflect-metadata\": \"^0.2.2\",\n    \"rxjs\": \"^7.8.2\",\n    \"zod\": \"^4.6.7\"\n  },\n  \"devDependencies\": {\n    \"@nestjs/cli\": \"^11.0.24\",\n    \"@nestjs/schematics\": \"^11.1.0\",\n    \"@nestjs/testing\": \"^11.2.12\",\n    \"@types/express\": \"^5.0.6\",\n    \"@types/jest\": \"^30.0.0\",\n    \"@types/node\": \"^24.19.4\",\n    \"jest\": \"^30.5.2\",\n    \"ts-jest\": \"^29.4.15\",\n    \"typescript\": \"~5.9.3\"\n  },\n  \"jest\": {\n    \"moduleFileExtensions\": [\"js\", \"json\", \"ts\"],\n    \"testRegex\": \".*\\\\.spec\\\\.ts$\",\n    \"transform\": { \"^.+\\\\.(t|j)s$\": \"ts-jest\" },\n    \"testEnvironment\": \"node\"\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"json","filename":"tsconfig.json"},"content":[{"type":"text","text":"{\n  \"compilerOptions\": {\n    \"module\": \"nodenext\",\n    \"moduleResolution\": \"nodenext\",\n    \"target\": \"ES2023\",\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true,\n    \"esModuleInterop\": true,\n    \"isolatedModules\": true,\n    \"strict\": true,\n    \"strictPropertyInitialization\": false,\n    \"skipLibCheck\": true,\n    \"sourceMap\": true,\n    \"outDir\": \"./dist\",\n    \"incremental\": true,\n    \"types\": [\"node\", \"jest\"]\n  },\n  \"include\": [\"src\", \"test\"]\n}"}]},{"type":"codeBlock","attrs":{"language":"json","filename":"tsconfig.build.json"},"content":[{"type":"text","text":"{\n  \"extends\": \"./tsconfig.json\",\n  \"include\": [\"src\"]\n}"}]},{"type":"codeBlock","attrs":{"language":"json","filename":"nest-cli.json"},"content":[{"type":"text","text":"{\n  \"$schema\": \"https://json.schemastore.org/nest-cli\",\n  \"collection\": \"@nestjs/schematics\",\n  \"sourceRoot\": \"src\",\n  \"compilerOptions\": { \"deleteOutDir\": true }\n}"}]},{"type":"codeBlock","attrs":{"language":"plaintext","filename":".env.example"},"content":[{"type":"text","text":"NODE_ENV=development\nPORT=3000\nMONGODB_URI=mongodb://localhost:27017/pierogi\nREDIS_URL=redis://localhost:6379\nCORS_ORIGINS=http://localhost:5173\n# openssl rand -hex 32\nKITCHEN_API_KEY=replace-with-a-long-random-secret-of-32-chars"}]},{"type":"codeBlock","attrs":{"language":"yaml","filename":"docker-compose.yml"},"content":[{"type":"text","text":"# Local infrastructure only – the app itself runs with `npm run start:dev`.\nservices:\n  mongo:\n    image: mongo:8\n    ports: [\"27017:27017\"]\n    volumes: [mongo-data:/data/db]\n  redis:\n    image: redis:8-alpine\n    ports: [\"6379:6379\"]\nvolumes:\n  mongo-data:"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Two "},{"type":"text","text":"tsconfig.json","marks":[{"type":"code"}]},{"type":"text","text":" options are mandatory for Nest: "},{"type":"text","text":"experimentalDecorators","marks":[{"type":"code"}]},{"type":"text","text":" (the old, \"legacy\" decorators) and "},{"type":"text","text":"emitDecoratorMetadata","marks":[{"type":"code"}]},{"type":"text","text":" – the compiler records constructor parameter types, and the DI container reads them to know what to inject. TypeScript stays on 5.9: Nest CLI 11 uses the compiler API, which TypeScript 7 no longer exposes."}]},{"type":"callout","attrs":{"variant":"warning","title":"BullMQ 6 needs ioredis"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Since version 6 BullMQ treats "},{"type":"text","text":"ioredis","marks":[{"type":"code"}]},{"type":"text","text":" as an optional dependency (you can pass another Redis client). Without "},{"type":"text","text":"npm install ioredis","marks":[{"type":"code"}]},{"type":"text","text":" the app starts, but the worker keeps logging \"BullMQ could not load the optional 'ioredis' package\". It is already listed in the "},{"type":"text","text":"package.json","marks":[{"type":"code"}]},{"type":"text","text":" above."}]}]},{"type":"heading","attrs":{"level":2,"id":"step-2-configuration-and-the-root-module"},"content":[{"type":"text","text":"Step 2. Configuration and the root module"}]},{"type":"paragraph","content":[{"type":"text","text":"ConfigModule.forRoot()","marks":[{"type":"code"}]},{"type":"text","text":" reads "},{"type":"text","text":".env","marks":[{"type":"code"}]},{"type":"text","text":" and environment variables, and the "},{"type":"text","text":"validate","marks":[{"type":"code"}]},{"type":"text","text":" option lets you plug in any validator. We use the same Zod schema as in Express – the app will not start with a missing "},{"type":"text","text":"MONGODB_URI","marks":[{"type":"code"}]},{"type":"text","text":" or a kitchen key that is too short."}]},{"type":"codeGroup","attrs":{"title":"Configuration, AppModule and bootstrap"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/config/env.ts"},"content":[{"type":"text","text":"import { z } from 'zod';\n\nconst EnvSchema = z.object({\n  NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),\n  PORT: z.coerce.number().int().min(1).max(65535).default(3000),\n  MONGODB_URI: z.string().startsWith('mongodb'),\n  REDIS_URL: z.string().startsWith('redis').default('redis://localhost:6379'),\n  CORS_ORIGINS: z.string().default('http://localhost:5173'),\n  // Shared secret for the kitchen tablet – long and random.\n  KITCHEN_API_KEY: z.string().min(32),\n});\n\nexport type Env = z.infer<typeof EnvSchema>;\n\n// Plugged into ConfigModule: the app refuses to start with a broken config.\nexport function validateEnv(raw: Record<string, unknown>): Env {\n  const result = EnvSchema.safeParse(raw);\n  if (!result.success) {\n    throw new Error(`Invalid environment configuration:\\n${z.prettifyError(result.error)}`);\n  }\n  return result.data;\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/app.module.ts"},"content":[{"type":"text","text":"import { BullModule } from '@nestjs/bullmq';\nimport { Module } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';\nimport { MongooseModule } from '@nestjs/mongoose';\nimport { ScheduleModule } from '@nestjs/schedule';\nimport { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';\nimport { DomainExceptionFilter } from './common/filters/domain-exception.filter';\nimport { LoggingInterceptor } from './common/interceptors/logging.interceptor';\nimport { Env, validateEnv } from './config/env';\nimport { OrdersModule } from './orders/orders.module';\n\n@Module({\n  imports: [\n    ConfigModule.forRoot({ isGlobal: true, cache: true, validate: validateEnv }),\n    MongooseModule.forRootAsync({\n      inject: [ConfigService],\n      useFactory: (config: ConfigService<Env, true>) => ({ uri: config.get('MONGODB_URI', { infer: true }) }),\n    }),\n    BullModule.forRootAsync({\n      inject: [ConfigService],\n      useFactory: (config: ConfigService<Env, true>) => ({ connection: { url: config.get('REDIS_URL', { infer: true }) } }),\n    }),\n    ScheduleModule.forRoot(),\n    ThrottlerModule.forRoot([{ ttl: 60_000, limit: 120 }]),\n    OrdersModule,\n  ],\n  providers: [\n    // Global enhancers registered as providers can use dependency injection.\n    { provide: APP_GUARD, useClass: ThrottlerGuard },\n    { provide: APP_FILTER, useClass: DomainExceptionFilter },\n    { provide: APP_INTERCEPTOR, useClass: LoggingInterceptor },\n  ],\n})\nexport class AppModule {}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/main.ts"},"content":[{"type":"text","text":"import { ValidationPipe } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { NestFactory } from '@nestjs/core';\nimport helmet from 'helmet';\nimport { AppModule } from './app.module';\nimport type { Env } from './config/env';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  const config = app.get<ConfigService<Env, true>>(ConfigService);\n\n  app.use(helmet());\n  app.enableCors({ origin: config.get('CORS_ORIGINS', { infer: true }).split(','), credentials: true });\n  app.setGlobalPrefix('api');\n  app.useGlobalPipes(\n    new ValidationPipe({\n      whitelist: true, // strip properties without decorators\n      forbidNonWhitelisted: true, // ...or rather reject them with 400\n      transform: true, // turn payloads into DTO class instances (and apply defaults)\n    }),\n  );\n  app.enableShutdownHooks(); // SIGTERM -> onModuleDestroy / beforeApplicationShutdown\n\n  await app.listen(config.get('PORT', { infer: true }));\n}\n\nvoid bootstrap();"}]}]},{"type":"paragraph","content":[{"type":"text","text":"What is going on here:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ConfigService<Env, true>","marks":[{"type":"code"}]},{"type":"text","text":" with "},{"type":"text","text":"{ infer: true }","marks":[{"type":"code"}]},{"type":"text","text":" gives typed reads – "},{"type":"text","text":"config.get('PORT', { infer: true })","marks":[{"type":"code"}]},{"type":"text","text":" returns a "},{"type":"text","text":"number","marks":[{"type":"code"}]},{"type":"text","text":", and a typo in a variable name does not compile."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"forRootAsync","marks":[{"type":"code"}]},{"type":"text","text":" + "},{"type":"text","text":"inject: [ConfigService]","marks":[{"type":"code"}]},{"type":"text","text":" is the standard way for an infrastructure module (Mongoose, BullMQ) to get its configuration from DI instead of reading "},{"type":"text","text":"process.env","marks":[{"type":"code"}]},{"type":"text","text":" in random places."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"APP_GUARD","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"APP_FILTER","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"APP_INTERCEPTOR","marks":[{"type":"code"}]},{"type":"text","text":" register global pipeline elements "},{"type":"text","text":"as providers","marks":[{"type":"bold"}]},{"type":"text","text":" – they can inject dependencies. "},{"type":"text","text":"app.useGlobalFilters(new X())","marks":[{"type":"code"}]},{"type":"text","text":" in "},{"type":"text","text":"main.ts","marks":[{"type":"code"}]},{"type":"text","text":" cannot."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ValidationPipe","marks":[{"type":"code"}]},{"type":"text","text":" with "},{"type":"text","text":"whitelist","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"forbidNonWhitelisted","marks":[{"type":"code"}]},{"type":"text","text":" rejects fields the DTO does not know (e.g. "},{"type":"text","text":"\"admin\": true","marks":[{"type":"code"}]},{"type":"text","text":"), and "},{"type":"text","text":"transform","marks":[{"type":"code"}]},{"type":"text","text":" turns JSON into DTO class instances."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"step-3-the-domain-and-ports"},"content":[{"type":"text","text":"Step 3. The domain and ports"}]},{"type":"paragraph","content":[{"type":"text","text":"Before touching Nest, we describe the pierogi shop in plain TypeScript: types, rules and domain errors. This file imports nothing from "},{"type":"text","text":"@nestjs/*","marks":[{"type":"code"}]},{"type":"text","text":" or "},{"type":"text","text":"mongoose","marks":[{"type":"code"}]},{"type":"text","text":"."}]},{"type":"codeGroup","attrs":{"title":"Order domain and ports"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/orders/domain/order.ts"},"content":[{"type":"text","text":"// Pure domain: no Nest, no Mongoose – just the rules of Halina's kitchen.\nexport const DISHES = ['ruskie', 'z-miesem', 'z-kapusta', 'z-jagodami'] as const;\nexport const ORDER_STATUSES = ['new', 'in-kitchen', 'ready', 'delivered', 'cancelled'] as const;\nexport const MAX_PIEROGI_PER_ORDER = 100;\n\nexport type Dish = (typeof DISHES)[number];\nexport type OrderStatus = (typeof ORDER_STATUSES)[number];\n\nexport interface OrderItem {\n  dish: Dish;\n  quantity: number;\n}\n\nexport interface Order {\n  id: string;\n  customerName: string;\n  phone: string;\n  items: OrderItem[];\n  note?: string;\n  status: OrderStatus;\n  createdAt: Date;\n}\n\nexport type NewOrder = Omit<Order, 'id' | 'status' | 'createdAt'>;\n\nexport class DomainError extends Error {\n  constructor(\n    readonly code: string,\n    message: string,\n  ) {\n    super(message);\n  }\n}\n\nexport class OrderNotFoundError extends DomainError {\n  constructor(id: string) {\n    super('ORDER_NOT_FOUND', `Order ${id} not found`);\n  }\n}\n\nexport class TooManyPierogiError extends DomainError {\n  constructor(total: number) {\n    super('TOO_MANY_PIEROGI', `Max ${MAX_PIEROGI_PER_ORDER} pierogi per order, got ${total}`);\n  }\n}\n\nexport class InvalidTransitionError extends DomainError {\n  constructor(from: OrderStatus, to: OrderStatus) {\n    super('INVALID_TRANSITION', `Cannot move order from \"${from}\" to \"${to}\"`);\n  }\n}\n\nconst TRANSITIONS: Record<OrderStatus, readonly OrderStatus[]> = {\n  new: ['in-kitchen', 'cancelled'],\n  'in-kitchen': ['ready', 'cancelled'],\n  ready: ['delivered'],\n  delivered: [],\n  cancelled: [],\n};\n\nexport function assertValidOrder(order: NewOrder): void {\n  const total = order.items.reduce((sum, item) => sum + item.quantity, 0);\n  if (total > MAX_PIEROGI_PER_ORDER) throw new TooManyPierogiError(total);\n}\n\nexport function assertTransition(from: OrderStatus, to: OrderStatus): void {\n  if (!TRANSITIONS[from].includes(to)) throw new InvalidTransitionError(from, to);\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/orders/domain/ports.ts"},"content":[{"type":"text","text":"import type { NewOrder, Order, OrderStatus } from './order';\n\n// Ports as abstract classes: they exist at runtime, so Nest can use them as DI tokens.\nexport abstract class OrdersRepository {\n  abstract create(order: NewOrder): Promise<Order>;\n  abstract findById(id: string): Promise<Order | null>;\n  abstract list(filter: { status?: OrderStatus; limit: number }): Promise<Order[]>;\n  abstract updateStatus(id: string, status: OrderStatus): Promise<Order | null>;\n  abstract deleteCancelledBefore(date: Date): Promise<number>;\n}\n\nexport abstract class KitchenTickets {\n  abstract send(order: Order): Promise<void>;\n}"}]}]}]},"toc":[{"id":"step-1-the-project-and-local-infrastructure","text":"Step 1. The project and local infrastructure","level":2,"locked":false},{"id":"step-2-configuration-and-the-root-module","text":"Step 2. Configuration and the root module","level":2,"locked":false},{"id":"step-3-the-domain-and-ports","text":"Step 3. The domain and ports","level":2,"locked":false},{"id":"step-4-the-application-service","text":"Step 4. The application service","level":2,"locked":true},{"id":"step-5-controller-dtos-and-pipes","text":"Step 5. Controller, DTOs and pipes","level":2,"locked":true},{"id":"step-6-guards-interceptors-and-exception-filters","text":"Step 6. Guards, interceptors and exception filters","level":2,"locked":true},{"id":"step-7-mongoose-schema-adapter-and-module","text":"Step 7. Mongoose: schema, adapter and module","level":2,"locked":true},{"id":"step-8-background-work-a-queue-and-a-schedule","text":"Step 8. Background work: a queue and a schedule","level":2,"locked":true},{"id":"step-9-tests-with-swapped-adapters","text":"Step 9. Tests with swapped adapters","level":2,"locked":true},{"id":"common-mistakes","text":"Common mistakes","level":2,"locked":true},{"id":"when-nestjs-and-when-not","text":"When NestJS, and when not","level":2,"locked":true},{"id":"check-yourself","text":"Check yourself","level":2,"locked":true},{"id":"what-s-next","text":"What's next","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":67,"visibleBlocks":20,"resources":[{"id":"6b0857b23c96f2d34d0b33bb","type":"repo","provider":"github","url":"https://github.com/nestjs/nest","embedUrl":null,"title":"nestjs/nest","description":"A progressive TypeScript framework for Node.js backends: from a small API in one file to efficient, scalable, enterprise-grade systems 🚀","author":"nestjs","thumbnailUrl":"https://opengraph.githubassets.com/1/nestjs/nest","durationSec":null,"lang":"en","topics":["microservices"],"techs":["node","javascript","typescript"],"tags":["framework","hacktoberfest","javascript","javascript-framework","microservices","nest","system-design","nestjs","node","nodejs"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2017-02-04T20:12:52.000Z","popularity":94,"verifiedAt":"2026-11-26T10:58:32.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:49.541Z","updatedAt":"2026-11-26T16:00:49.541Z"},{"id":"6b0857b23c96f2d34d0b357d","type":"repo","provider":"github","url":"https://github.com/jmcdo29/testing-nestjs","embedUrl":null,"title":"jmcdo29/testing-nestjs","description":"A repository to show off to the community methods of testing NestJS including Unit Tests, Integration Tests, E2E Tests, pipes, filters, interceptors, GraphQL, Mongo, TypeORM, and more!","author":"jmcdo29","thumbnailUrl":"https://opengraph.githubassets.com/1/jmcdo29/testing-nestjs","durationSec":null,"lang":"en","topics":["cqrs"],"techs":["node","typescript"],"tags":["cqrs","examples","graphql","hacktoberfest","interceptor","mongo","testing","api-design","nestjs","pipes"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2019-07-25T21:14:54.000Z","popularity":67,"verifiedAt":"2026-11-26T10:58:16.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"},{"id":"6b0857b23c96f2d34d0b35ac","type":"repo","provider":"github","url":"https://github.com/Sairyss/backend-best-practices","embedUrl":null,"title":"Sairyss/backend-best-practices","description":"Best practices, tools and guidelines for backend development. Code examples in TypeScript + NodeJS","author":"Sairyss","thumbnailUrl":"https://opengraph.githubassets.com/1/Sairyss/backend-best-practices","durationSec":null,"lang":"en","topics":[],"techs":["node","javascript","typescript"],"tags":["backend","best-practices","api","software-design","typescript","javascript","devops","nodejs","nestjs","development"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2021-12-16T11:12:26.000Z","popularity":65,"verifiedAt":"2026-11-26T10:55:56.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"},{"id":"6b0857b33c96f2d34d0b3602","type":"repo","provider":"github","url":"https://github.com/pvarentsov/typescript-clean-architecture","embedUrl":null,"title":"pvarentsov/typescript-clean-architecture","description":"It is my attempt to create Clean Architecture based application in TypeScript.","author":"pvarentsov","thumbnailUrl":"https://opengraph.githubassets.com/1/pvarentsov/typescript-clean-architecture","durationSec":null,"lang":"en","topics":["clean-architecture"],"techs":["node","typescript"],"tags":["back-end","clean-architecture","clean-code","e2e-testing","nestjs","nodejs","software-architecture","testing","typeorm","typescript"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2020-07-07T17:19:36.000Z","popularity":61,"verifiedAt":"2026-11-26T10:57:47.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"},{"id":"6b0857ab3c96f2d34d0b326e","type":"package","provider":"npm","url":"https://www.npmjs.com/package/@nestjs/cqrs","embedUrl":null,"title":"@nestjs/cqrs","description":"CQRS for NestJS: command, query and event buses, sagas.","author":"","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["cqrs","event-driven-architecture"],"techs":["node"],"tags":["cqrs"],"price":"free","featured":false,"featuredOrder":29,"packageName":"@nestjs/cqrs","source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:43.175Z","updatedAt":"2026-11-26T16:00:43.175Z"}],"challenges":[],"attachments":[],"hasCode":true,"repoUrl":null,"series":[],"prev":null,"next":null,"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}