Nishanth
Nishanth

Reputation: 381

Joi error validation throws error in node js

I am using JOI to validate request object as below (JOI version used "joi": "^17.2.1")

const Joi=require('joi');
app.post('/api/saveMovieList',(req,res)=>{
  var schema = Joi.object().keys({
    name: Joi.string().min(5).max(10).required()
  });
  
  constr result=Joi.validate(req.body, schema);
  console.log(result);
});

getting error as Joi.validate is not a function

If I use

constr result=schema.validate(req.body, schema);
console.log(result);

getting error message as Invalid message options

Can someone help me to fix this issue?

Upvotes: 1

Views: 1652

Answers (2)

Snehal Tembare
Snehal Tembare

Reputation: 21

I upgrade the Joi version to 17.13.1 Following code works for me

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

Upvotes: 0

Nishanth
Nishanth

Reputation: 381

Following code solved my issue

const schema = Joi.object({
        name: Joi.string().min(6).required()
    });
        
    const validation = schema.validate(req.body);

Upvotes: 0

Related Questions