3

I have my API key set to a variable in an apikey.js file, and I reference the variable in another javascript file where the API key is supposed to be.

I added apikey.js to .gitignore so that people wouldn't see it when I pushed it to my (public) github account.

However, when I try to deploy, the app doesn't work because of the .gitignore.

How can I continue to push up files omitting the API key to my repo on git while deploying on heroku?

1

1 Answer 1

6

use https://github.com/ddollar/heroku-config, and you can keep your secrets in a file called .env and ignore that in .gitignore

Install it with heroku plugins:install git://github.com/ddollar/heroku-config.git

You can run heroku config:pull --overwrite --interactive to generate an initial .env file that includes your service secrets, etc, and heroku config:push to save it, remotely.

I am assuming that you are using node, since your config file is javascript. To get the values in your .env file in node use process.env. For example to connect to your mongolab in mongoose:

mongoose.connect(process.env.MONGOLAB_URI); 

There is more about all this here: https://devcenter.heroku.com/articles/config-vars#local-setup

Sign up to request clarification or add additional context in comments.

1 Comment

Does this answer your question?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.