ozygz
ozygz

Reputation: 91

i get 'Joi.object.keys is not a function' error message from nodemon when i try to use .keys()

When i try to use joi.object.keys i get error.I used joi.object.keys function in my previous project but i did not get any error.

const checkSchema = Joi.object.keys({ // error is here
email: Joi.string().email({ minDomainSegments: 2 }),
password: Joi.string().pattern(new RegExp('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,}$')),
confirmPassword: Joi.string().valid(Joi.ref('password')).required(),

});

Upvotes: 2

Views: 1357

Answers (2)

Ali Khan Mehboob
Ali Khan Mehboob

Reputation: 11

There is a possibility that you might be using old version of JOI in your previous projects. In their latest documentation they have removed the object keyword when initializing. You should try this:

const Joi = require("joi");
const checkSchema = Joi.object().keys({ // I changed here
  email: Joi.string().email({ minDomainSegments: 2 }),
  password: Joi.string().pattern(
    new RegExp(
      "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,}$"
    )
  ),
  confirmPassword: Joi.string().valid(Joi.ref("password")).required(),
});

Documentation Link: https://joi.dev/api/?v=17.4.2

Upvotes: 1

Nikhil Unni
Nikhil Unni

Reputation: 779

May be due to version change. Have you tried Joi.object().keys({.......})?. This will work. Also please share your version if the above solution didn't work

Upvotes: 3

Related Questions