I am using an .env file to hold environment variables for the server. This works if I run the server with foreman start. But it doesn't work with nodemon.
I would like to use nodemon instead because it restarts automatically when you modify the server. How can I get nodemon to work with .env files?
You can create an. env file in the application's root directory that contains key/value pairs defining the project's required environment variables. The dotenv library reads this.
env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.
npm i dotenv
.env
file and your variables insideAdd the script to execute
"dev": "nodemon -r dotenv/config ./app/index.js " or "start": "node -r dotenv/config ./app/index.js "
Run the app using npm run dev
or npm run start
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With