text: const Joi = require('joi');
  
  // require and configure dotenv, will load vars in .env in PROCESS.ENV
  require('dotenv').config();
  
  // define validation for all the env vars
  const envVarsSchema = Joi.object({
    NODE_ENV: Joi.string()
      .allow(['development', 'production', 'test', 'provision'])
      .default('development'),
    PORT: Joi.number().default(6060),
    MONGOOSE_DEBUG: Joi.boolean().when('NODE_ENV', {
      is: Joi.string().equal('development'),
      then: Joi.boolean().default(true),
      otherwise: Joi.boolean().default(false)
    }),
    JWT_SECRET: Joi.string()
      .required()
      .description('JWT Secret required to sign'),
    MONGO_HOST: Joi.string()
      .required()
      .description('Mongo DB host url'),
    MONGO_PORT: Joi.number().default(27017),
    TWILIO_ACCOUNT_SID: Joi.string(),
    TWILIO_AUTH_TOKEN: Joi.string(),
    TWILIO_NUMBER_TWO: Joi.string()
  })
    .unknown()
    .required();
  
  const { error, value: envVars } = Joi.validate(process.env, envVarsSchema);
  if (error) {
    throw new Error(`Config validation error: ${error.message}`);
  }
  
  const config = {
    env: envVars.NODE_ENV,
    port: envVars.PORT,
    mongooseDebug: envVars.MONGOOSE_DEBUG,
    jwtSecret: envVars.JWT_SECRET,
    mongo: {
      host: envVars.MONGO_HOST,
      port: envVars.MONGO_PORT
    },
    accountSid: envVars.TWILIO_ACCOUNT_SID,
    authToken: envVars.TWILIO_AUTH_TOKEN,
    phoneNumber: envVars.TWILIO_NUMBER_TWO
  };
  
  module.exports = config;
  