title: Use data from .env file in main.ts - NestJS
body: <p>NestJS allows us to read .env file through ConfigModule and I can do that easily in my modules with code like following</p>
  <pre><code>@Module({
    imports: [ConfigModule.forRoot()],
    providers: [
      NVFullNameSearchService,
      NVPartialNameSearchService,
      NVPersistService,
    ],
    controllers: [NvController],
  })
  </code></pre>
  <p>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?</p>
  <pre><code>const microserviceOptions = {
    name: 'plscorecard',
    transport: Transport.REDIS,
    options: {
      url: 'redis://localhost:6379',
    },
  };
  async function bootstrap() {
    const app = await NestFactory.createMicroservice(
      NVModule,
      microserviceOptions,
    );
    app.listen(() =&gt; {
      logger.log('NameVerification Redis microservice is listening ... ');
    });
  }
  bootstrap();
  </code></pre>
  <p>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?</p>