Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Vatsalya-singhi/8e45ba66e76b49baa29e912d98bbd307 to your computer and use it in GitHub Desktop.
Save Vatsalya-singhi/8e45ba66e76b49baa29e912d98bbd307 to your computer and use it in GitHub Desktop.
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import * as Joi from 'joi';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true, // Makes config available across the app
envFilePath: `.env.${process.env.NODE_ENV || 'development'}`, // Load specific .env file based on NODE_ENV
ignoreEnvFile: process.env.NODE_ENV === 'production', // Ignore .env in production (use external env variables)
expandVariables: true, // Enables ${VAR_NAME} expansion in .env files
validationSchema: Joi.object({
PORT: Joi.number().default(3000), // Ensures PORT is a number, defaults to 3000
DATABASE_URL: Joi.string().required(), // Ensures DATABASE_URL is provided
JWT_SECRET: Joi.string().min(10).required(), // Requires JWT_SECRET with a min length of 10
}),
}),
],
})
export class AppModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment