Put in order · NestJS course · Module 1: NestJS Basics

Steps for Adding DTO Validation

Arrange the steps for adding DTO validation in NestJS:

Items to put in order

  • Adding validation decorators to DTO class fields
  • Activating ValidationPipe in main.ts
  • Using DTO in the controller: @Body() dto: CreateDto
  • Install: npm install class-validator class-transformer
Show the answer

Correct order:

  1. Install: npm install class-validator class-transformer
  2. Using DTO in the controller: @Body() dto: CreateDto
  3. Adding validation decorators to DTO class fields
  4. Activating ValidationPipe in main.ts