0

I have just started using Heroku and I think that I may be facing a potential problem. I have a GitHub repository that contains the code for a Rest API that I have made. However, a config file has not been published as it contains the password to connect to my database (MongoDB Atlas). I want to port my Node.js API to Heroku, but I do not think that just deploying the code from GitHub will work. What should I do? I have Git and the Heroku CLI installed, and use Linux.

Diogenis Siganos
  • 779
  • 7
  • 17

1 Answers1

2

Use Environment variables on Heroku. As you rightly mentioned in your question, it is not a good idea to push credentials and other sensitive information in code repositories. So instead of pushing .env file, just create Environment Variables on Heroku. It can be done using Heroku web interface or using Heroku CLI too.

Sample commands on CLI will look like

To get existing config variables

heroku config

To get a specific config variable

heroku config:get GITHUB_USERNAME

To set a config variable

heroku config:set GITHUB_USERNAME=joesmith

To delete a config variable

heroku config:unset GITHUB_USERNAME

To access variable inside your Node.js app,

process.env.GITHUB_USERNAME

Configuration and Config Vars

Bilal Akbar
  • 4,659
  • 1
  • 18
  • 29