Don't check in your API keys into your git repo, ever.
- If you've already checked in an API key for a service to your git repo, generate a new key
- Create a file called
.env
in your project's root directory - Store your API keys in your
.env
files in this format:API_KEY_NAME=api_key_value
- Anywhere you had written your key in your js files, use the expression
process.env.API_KEY_NAME
to get the value of the API key from your environment - If you have multiple keys, each key-value pair should be on a new line - See Environment
- Add your
.env
file to.gitignore
so that you don't check in your.env
file into your git repo - Create a
Procfile_dev
file and addweb: nodemon index.js
to it. - Start your app locally with
foreman
by writingforeman start -f Procfile_dev
- From now on your apps will start on port
5000
so please go tohttp://localhost:5000
in your browser to see your app. - Set your environment variables on heroku by writing the following command in your terminal:
heroku config:set API_KEY_NAME=api_key_value