NestJS allows us to read .env file through ConfigModule and I can do that easily in my modules with code like following
@Module({
imports: [ConfigModule.forRoot()],
providers: [
NVFullNameSearchService,
NVPartialNameSearchService,
NVPersistService,
],
controllers: [NvController],
})
But above code is more to deal within modules, how can I read content from .env file in main.ts. Say I need to set port and host for my Redis service?
const microserviceOptions = {
name: 'plscorecard',
transport: Transport.REDIS,
options: {
url: 'redis://localhost:6379',
},
};
async function bootstrap() {
const app = await NestFactory.createMicroservice(
NVModule,
microserviceOptions,
);
app.listen(() => {
logger.log('NameVerification Redis microservice is listening ... ');
});
}
bootstrap();
As you can see app is yet to be created in this case. Should I directly use dotenv? As you'd expect in any enterprise environment, I have different env files for DEV, QA, UAT and Production. What's the easiest/right way to achieve it?