Using .env in NestJs

Visakh Vijayan - Jun 13 '21 - - Dev Community

Using the .env file in NestJs can't be easier. All you have to do is this

npm i --save @nestjs/config
Enter fullscreen mode Exit fullscreen mode

Go to the app.module.ts file which is the starting module being called. Add add this inside your imports array

ConfigModule.forRoot()
Enter fullscreen mode Exit fullscreen mode

Create a .env file in the root.

Start accessing your variables using process.env.your-variable-name

Happy programming!!!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .