As I mentioned before that we can just use ConfigModule with .env file.

But sometimes we need to access .env variables at the beginning of time, when the module is not fully loaded yet.

Then we manually load it in the top of the main.ts file.

import * as dotenv from 'dotenv';
dotenv.config();

This post is imported from: https://thebrownbox.hashnode.dev/manual-load-env-file-in-nestjs