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
Create a .env file in the root.
Start accessing your variables using process.env.your-variable-name