DEV Community

Cover image for Using .env in NestJs
Visakh Vijayan
Visakh Vijayan

Posted on

Using .env in NestJs

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!!!

Discussion (1)

Collapse
tylerjusfly profile image
Momoh Taiwo Tyler

What is going to be in the forRoot() and when you mean create the .env file in the root , you meanttroot folder?