دورة Node JS API - Node JS API : #08 - Input Validation
Master Node.js API Development: Unleash Your Full-stack Potential!
4.0(0)
5 learners
What you'll learn
Develop foundational skills in creating and managing HTTP servers using Node.js.
Gain proficiency in using Express.js to build and structure RESTful APIs effectively.
Understand how to implement and manage MongoDB database connections with Mongoose.
Learn to secure and optimize Node.js applications using middleware and JWT authentication.
In this part we validate the data that comes from the client with Joi package.
If you want to have custom message with Joi you should use messages() method.
Example:
------------------------------------------------------------------------------------------------------------------------
const schema = Joi.object({
username: Joi.string().trim().min(3).max(100).required().messages({
'any.required': 'الاسم مطلوب',
'string.base': 'الاسم لازم يكون من نوع نص',
'string.empty': 'رجاء ادخال الاسم',
'string.min': 'لا يجوز الاسم يكون اقل من ثلاثة حروف',
'string.max': 'لا يجوز الاسم يكون اكثر من مئه حروف',
}),
});
--------------------------------------------------------------------------------------------------------------------------
Continue this lesson in the app
Install CourseHive on Android or iOS to keep learning while you move.