bgardne7
bgardne7

Reputation: 93

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?

Upvotes: 0

Views: 2293

Answers (1)

Chris
Chris

Reputation: 137114

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.

Upvotes: 2

Related Questions