Manual load .env file in NestJS

The Brown BoxThe Brown Box
1 min read

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();
0
Subscribe to my newsletter

Read articles from The Brown Box directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

The Brown Box
The Brown Box