0
0
NestJSframework~10 mins

Validation with Joi in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Joi for validation.

NestJS
import * as [1] from 'joi';
Drag options to blanks, or click blank then click option'
Aexpress
BJoi
Cnestjs
Dclass-validator
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from 'express' or 'nestjs' instead of 'joi'.
Using 'class-validator' which is a different validation library.
2fill in blank
medium

Complete the code to define a Joi schema for a username that is a required string.

NestJS
const schema = Joi.object({ username: Joi.[1]().required() });
Drag options to blanks, or click blank then click option'
Anumber
Barray
Cboolean
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using number() or boolean() instead of string().
Forgetting to call required() to make the field mandatory.
3fill in blank
hard

Fix the error in the validation pipe setup by completing the missing property.

NestJS
app.useGlobalPipes(new ValidationPipe({ whitelist: [1] }));
Drag options to blanks, or click blank then click option'
Afalse
Bnull
Ctrue
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Setting whitelist to false or null disables property filtering.
Leaving whitelist undefined means no filtering happens.
4fill in blank
hard

Fill both blanks to create a Joi schema for an email that is required and must be valid.

NestJS
const schema = Joi.object({ email: Joi.[1]().[2]() });
Drag options to blanks, or click blank then click option'
Astring
Bemail
Crequired
Dvalid
Attempts:
3 left
💡 Hint
Common Mistakes
Using email() instead of string() (email is a validator, not a type).
Forgetting to add required().
5fill in blank
hard

Fill all three blanks to create a Joi schema for a password that is a required string with minimum length 8.

NestJS
const schema = Joi.object({ password: Joi.[1]().min([2]).[3]() });
Drag options to blanks, or click blank then click option'
Astring
B8
Crequired
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using number() instead of string().
Forgetting to call required().
Setting min to a string instead of a number.