I'm in the process of setting up Nest.js project and I look for the efficient solution of defining Node environment which is used by the ConfigService
for loading environment variables:
import { Module } from '@nestjs/common';
import { ConfigService } from './config.service';
@Module({
providers: [
{
provide: ConfigService,
useValue: new ConfigService(`environments/${process.env.NODE_ENV}.env`)
}
],
exports: [ConfigService]
})
export class ConfigModule {}
Right now I'm defining it directly in the npm scripts (for example "start:dev": "NODE_ENV=development nodemon"
), but I'm wondering if there is some better approach for handling different environments instead of appending it in every script?