简体   繁体   中英

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?

Following code solved my issue

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM