Joi version 17+

Hi,

 //  Joi Version -> 17
     app.post("/api/courses", (req, res) => {
        
        const name = { name: req.body.name };

        const schema = Joi.object({ name: Joi.string().min(3).required() });

        const result = schema.validate(name);

        if (result.error) {

          res.status(400).send(result.error.details[0].message);

        }

And the rest would be the same

3 Likes