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;
}

Explanation

app.useGlobalPipes(new ValidationPipe()) validates every @Body(), @Query() and @Param() typed with a DTO.

Further reading

Problem with a question

NestJS · Junior · question 31

Test yourself

Take the NestJS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz