DEV Community

loading...
Cover image for Using .env in NestJs

Using .env in NestJs

Visakh Vijayan
Willing to learn anything and everything exciting. Always awake. Skips food for fun.
・1 min read

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 (0)