Using the .env file in NestJs can't be easier. All you have to do is this
npm i --save @nestjs/config
Go to the app.module.ts file which is the starting module being called. Add add this inside your imports array
ConfigModule.forRoot()
Create a .env file in the root.
Start accessing your variables using process.env.your-variable-name
Happy programming!!!
Top comments (1)
What is going to be in the forRoot() and when you mean create the .env file in the root , you meanttroot folder?