API and Microservice - Is it ok to use github + heroku setup?

Is it safe for me to host my project on github and heroku?
Because I think Some of these projects will need mongodb in that case it’s not safe to upload my private key for mongodb.

I want to use github because of obvious reasons.

Hello there,

Yes, it is ok for you to use GitHub + Heroku.

No, it is not ok for you to upload your API/URI keys/passwords to GitHub. However, you do not need to do this to be able to use a database.

This is what I do (and I assume, most other devs):

  1. Ensure you have a .gitignore file with .env in it
  2. Create a .env file with your secret keys (example: MONGO_URI=mongo@me.1234)
  3. Access the secret key with process.env.MONGO_URI
  4. Heroku allows secret keys (environment variables) to be added in the settings of your app. You do not need to change anything in your code.

I suggest you research:

  1. How to use .gitignore files
  2. How to use .env files
  3. How Heroku deals with environment variables

Hope this clarifies.

1 Like