I'm trying to run heroku locally through the heroku local
command. However, this doesn't use the environment variables in heroku config
.
When I run heroku local
I would like my local server to use the same environment variables found in heroku config
.
I would like my local server to mimic the real world server; thats' why I'm trying to do this.
The whole point of environment variables is that they're environment-specific. In many cases it doesn't make much sense to use the same ones in development as in production (e.g. your development database should probably be different from your production one, and you probably don't really want to send email in development).
In any case, heroku local
supports loading environment variables from a .env
file. You can create a local .env
file from your production environment variables:
Sometimes you may want to use the same config var in both local and Heroku environments. For each config var that you want to add to your
.env
file, use the following command:heroku config:get CONFIG-VAR-NAME -s >> .env
Do not commit the
.env
file to source control. It should only be used for local configuration. Update your.gitignore
file to exclude the.env
file.Keep in mind that your deployed production app may be connecting to different services than your local development app. For example, your deployed production app might have a
DATABASE_URL
config var that references a Heroku Postgres database, but your local app might have aDATABASE_URL
variable in the.env
file that references your local installation of Postgres.