Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.env does not contain config variables on Heroku

I have a few apps on Heroku. All of them use GruntJS to build assets and deploy to S3. One app has been working fine for quite some time.

The other apps have a problem where I can not read my config variables from the Gruntfile. When I use Heroku's toolbelt to view my setup, I see:

$ heroku config --app mydevapp --account personal
=== mydevapp Config Vars
AWS_ACCESS_KEY:         #########     
AWS_BUCKET:             #########
AWS_SECRET_KEY:         #########
BUILDPACK_URL:          https://github.com/ddollar/heroku-buildpack-multi.git
DATABASE_URL:           #########
PAPERTRAIL_API_TOKEN:   #########
TEST:                   test

Which is great. However none of these variables are available to me from Grunt. When I console.log(process.env) from the Gruntfile, I see:

{ GEM_HOME: '/tmp/build_e26d1d60-d447-40d8-b09b-02d3758a6027/.gem/ruby/1.9.1',
  SHELL: '/bin/bash',
  SSH_CLIENT: '10.207.46.127 55868 50678',
  GROUP: 'production',
  DEPLOY: 'production',
  STACK: 'cedar',
  SHLVL: '3',
  HOME: '/app',
  CPPPATH: '/tmp/node-node-hP8q/include',
  _: '/tmp/build_e26d1d60-d447-40d8-b09b-02d3758a6027/node_modules/grunt-cli/bin/grunt' 
}

There are some other vars in there, but I'm not sure what is safe to show. I don't see ANY of my config vars listed.

I have no idea what the difference is between my working app, and the two apps that don't have config vars in the process.env variable.

I've read that using Grunt in this manner isn't really the best idea, but it is what we have setup. Of course that could change if need be.

Any ideas? Is there anything I need to clarify?

like image 313
ryanday Avatar asked Oct 24 '13 15:10

ryanday


People also ask

Does Heroku use .env file?

Heroku Local is a command-line tool to run Procfile-backed apps. It is installed automatically as part of the Heroku CLI. Heroku Local reads configuration variables from a . env file.

How do I access Heroku config vars in Python?

Heroku's environment variables are called config vars. To set a config var, navigate to the Settings tab of your app's dashboard, and click Reveal Config Vars.

How do I access Heroku config vars in react?

If you use Create React App (or react-scripts), prepend the variable with REACT_APP_ , for instance, REACT_APP_BASE_URL , and Create React App automatically uses its value during the build process, making it then accessible in the process.


1 Answers

Heroku does not expose the config variables to the build stage by default. It you want this, you'll have to enable the user-env-compile lab by issuing:

heroku labs:enable user-env-compile -a myapp

Docs: https://devcenter.heroku.com/articles/labs-user-env-compile

like image 156
Nitzan Shaked Avatar answered Oct 06 '22 00:10

Nitzan Shaked