Search code examples
mongodbherokugithub

Hide mongodb password using heroku so I can also push to public repo on github


I am trying to be able to push to heroku and a public github repo without having my database password revealed on github, and without having to change the .gitignore every time.

In the URI for mongodb on heroku, it suggests doing mongodb://<username>:<password>@<address> in your production environment script.

Is there a way to hide this on github?


Solution

  • I have figured out the answer!

    In your production configuration for Heroku, use your Heroku "Config Variables" for your database URI.

    For example, if you use MongoHQ, use process.env.MONGOHQ_URL for your URI, no password or username needed because it is connecting to the local server.

    If you use MongoLabs use process.env.MONGOLAB_URI.

    Hope this helps someone, I definitely found it useful!