Heroku config vars/env vars not working (using node.js)

1.7k views Asked by At

The following setup does not work:

Setting a config var either via the dashboard or via

heroku config:set TESTVAR=123

using heroku config shows the variable is set.

But then logging into the container using

heroku ps:exec

and logging out the env vars should show the variable set via config:set but it does not:

node -e "console.log(process.env)"

Also using

export

does not show the environment variable.

I tried defining the variable in app.json but to no avail:

"env": { "TESTVAR":{ "required": true },

According to the documentation this should work but unfortunately it does not. Any help is appreciated.

1

There are 1 answers

0
Raphael PICCOLO On BEST ANSWER

Try heroku run env instead.

According to the documentation: "The SSH session created by Heroku Exec will not have the config vars set as environment variables (i.e., env in a session will not list config vars set by heroku config:set)."

see this for more information How to get environment variables in live Heroku dyno