Search code examples
reactjsapiherokuapi-key

How do I use Config Vars in Heroku to get my API key to work?


So I have .env added to my .gitignore and in my .env file I have

REACT_APP_WEATHER_API_KEY=123456

This was a recent add on, I already have this app fully deployed and working on Heroku. Do I just go to settings => Config Vars and add key=REACT_APP_WEATHER_API_KEY and value=123456? How would I go about implementing my API key into Heroku within the settings?


Solution

  • You don't need key= or value=, just set REACT_APP_WEATHER_API_KEY to 123456 directly, either via heroku config:set:

    heroku config:set REACT_APP_WEATHER_API_KEY=123456
    

    or the dashboard.

    The .env file you're using in development and Heroku's config vars are both just convenient ways of setting environment variables:

    Config vars are exposed to your app’s code as environment variables. For example, in Node.js you can access your app’s DATABASE_URL config var with process.env.DATABASE_URL.

    As long as you are using the REACT_APP_WEATHER_API_KEY environment variable when your React application builds, or at runtime from your back-end (if you have one), you should be in business.