NestJS · Junior · Question 31 of 75
How is request body validation usually set up?
export class CreateUserDto {
@IsEmail()
email: string;
@IsString()
@MinLength(8)
password: string;
}- 1Write
ifchecks in every controller - ✓Correct answer: Decorate DTO fields with
class-validatorrules and enableValidationPipe(often globally) - 3Nest validates everything automatically without setup
Explanation
app.useGlobalPipes(new ValidationPipe()) validates every @Body(), @Query() and @Param() typed with a DTO.