Created
March 27, 2025 18:53
-
-
Save Vatsalya-singhi/8e45ba66e76b49baa29e912d98bbd307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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