0
0
NestJSframework~5 mins

ValidationPipe setup in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of ValidationPipe in NestJS?
ValidationPipe automatically checks incoming data against defined rules to ensure it is valid before processing. It helps catch errors early and keeps the app safe.
Click to reveal answer
beginner
How do you apply ValidationPipe globally in a NestJS application?
Use app.useGlobalPipes(new ValidationPipe()) inside the main.ts file after creating the app instance.
Click to reveal answer
beginner
Which package must be installed to use ValidationPipe with decorators like @IsString()?
You need to install class-validator and class-transformer packages to use ValidationPipe with decorators.
Click to reveal answer
intermediate
What does the 'whitelist' option do in ValidationPipe?
It removes any properties from the input object that are not defined in the DTO, helping to keep data clean and safe.
Click to reveal answer
intermediate
How can you enable automatic transformation of input data types in ValidationPipe?
Set the 'transform' option to true in ValidationPipe. This converts input strings to the expected types defined in DTOs.
Click to reveal answer
Where do you typically set up ValidationPipe globally in a NestJS app?
AInside each controller method
BIn main.ts using app.useGlobalPipes()
CIn the service class constructor
DIn the module imports array
Which decorator is used to mark a class property as a string for validation?
A@IsString()
B@IsBoolean()
C@IsNumber()
D@IsDate()
What happens if ValidationPipe receives invalid data?
AIt throws a BadRequestException
BIt silently ignores the error
CIt logs a warning but continues
DIt converts data to default values
What does setting 'forbidNonWhitelisted' to true do in ValidationPipe?
AIgnores validation rules
BRemoves extra properties silently
CAllows extra properties without error
DThrows an error if extra properties exist
Which packages are required to use ValidationPipe decorators?
Aexpress and body-parser
Btypeorm and graphql
Cclass-validator and class-transformer
Drxjs and reflect-metadata
Explain how to set up ValidationPipe globally in a NestJS app and why it is useful.
Think about where the app starts and how to apply validation everywhere.
You got /4 concepts.
    Describe the purpose of the 'whitelist' and 'transform' options in ValidationPipe.
    Consider how these options clean and convert data.
    You got /3 concepts.