How to add .env file or otherwise set environment variables in a Heroku app?
There is no need for an .env
file on Heroku. In fact, such a file won't work very well since
- Heroku gets all of its files from your Git repository,
- has an ephemeral filesystem, meaning that changes to files like
.env
will be quickly lost, and - the
.env
file won't be available on other dynos if you scale your app
As such, creating an .env
file on Heroku isn't a good approach.
Instead, you can use its built-in support for environment variables, using heroku config:set <var> <value>
or its web UI. Either way, you'll get a regular environment variable.