0
a: {
  b: 'c'
}

I'm trying to validate it using Joi, inside my module:

    ConfigModule.forRoot({
      envFilePath: ['config.env'],
      load: [generalConfig],
      validationSchema: Joi.object({
        a: Joi.object({
          b: Joi.number().min(0).max(2).required(),
        }),
      }),
      validationOptions: {
        allowUnknown: true,
        abortEarly: true,
      },
      cache: false,
    }),

I get no error/warning at all. If I change the validationSchema to:

validationSchema: Joi.object({
  b: Joi.number().min(0).max(2).required(),
}),

And this is the .env content:

a: {
    "b": 1,
}

I get the error as always. Any idea?

MoreOver
  • 381
  • 1
  • 5
  • 17
  • how's the content of your 'config.env'? I've never saw one with JSON in it. Maybe yaml fits better – Micael Levi Sep 15 '21 at 19:22
  • Added it at the bottom. I'd like to use JSON format, if possible. – MoreOver Sep 15 '21 at 19:25
  • that package uses `dotenv`. Read more about the syntax of the env. file here: https://github.com/motdotla/dotenv#rules basically, you can't write it like this (see https://stackoverflow.com/questions/56277661/i). You could write your own ConfigModule that loads json instead – Micael Levi Sep 15 '21 at 19:31
  • I see. Thank you! – MoreOver Sep 15 '21 at 19:35

0 Answers0