I'm trying to set configuration variables on my project using the official documentation.
I added the following line to my app.module.ts imports:
ConfigModule.forRoot({
isGlobal: true
}),
I created a .env file at the root of my project with the following content:
MY_VARIABLE=myself
And I use dependecy injection to get access to the configuration service:
constructor(private configService: ConfigService) {}
However the following line logs 'Env variable: undefined'
console.log('Env variable: ', this.configService.get<any>('MY_VARIABLE'));
Several scenarios:
.env
file.env
is incorrectly defined.env
located outside the server's root pathdotenv
packagefunctions
(or other deployable folder) the .env
is missing (even though it's in the root location it has to be there too)