Complete the code to import Joi for validation.
const Joi = require('[1]');
Joi is imported using the package name 'joi' to use its validation features.
Complete the code to define a Joi schema for a required string 'username'.
const schema = Joi.object({ username: Joi.[1]().required() });Use Joi.string() to specify that 'username' must be a string.
Fix the error in validating the request body using Joi.
const { error } = schema.[1](req.body);The correct Joi method to validate data is 'validate'.
Fill both blanks to create a middleware that validates 'email' as a required string and calls next() if valid.
const validateEmail = (req, res, next) => {
const schema = Joi.object({ email: Joi.[1]().[2]() });
const { error } = schema.validate(req.body);
if (error) return res.status(400).send(error.details[0].message);
next();
};Use Joi.string() to specify the type and required() to make it mandatory.
Fill all three blanks to define a Joi schema for 'password' with minimum length 8, required, and validate it.
const schema = Joi.object({ password: Joi.[1]().min([2]).[3]() });
const { error } = schema.validate(req.body);Password should be a string, have a minimum length of 8, and be required.
