I would configure enivrement variables in nestjs as mentioned in documentation here:
in my service constructor I get env file path
import * as dotenv from 'dotenv';
import * as fs from 'fs';
export class ConfigService {
private readonly envConfig: { [key: string]: string };
constructor(filePath: string) {
this.envConfig = dotenv.parse(fs.readFileSync(filePath))
console.log(this.envConfig)
}
get(key: string): string {
return this.envConfig[key];
}
}
Then in config module I set the config service
providers: [
{
provide: ConfigService,
useValue: new ConfigService(`${process.env.NODE_ENV}.env`),
},
],
exports: [ConfigService],
})
Current behavior
Actually I get process.env.NODE_ENV value undefined
Expected behavior
get env variable path in process.env.NODE_ENV