Connect to the database in Heroku node.js application without revealing authentication data on git

I have a node.js application that I clicked on Heroku. It uses MongoDB for storage. Heroku offers free MongoDB as an add-on to which your application can connect. Now my question is that the connection string has this format: mongodb: // dbuser: dbpass @host: port / dbname, and since Heroku uses git for push, how can I push my code to the public GitHub repository without showing my name username and password to everyone?

Is there no way to open the database, but only for connections coming from my Heroku application?

I must admit that I am rather confused about this issue.

+6
source share
2 answers

You will want to read Configuration and Configs at Dev Heroku Center. Heroku expects and recommends that you use configuration variables (configured on the Heroku application itself, not the code base) to protect sensitive data, such as passwords. Use heroku config:set VARIABLE=value , but note that most Heroku hadrons automatically add authentication data to your configuration variables when they are created. You can verify what was installed using the heroku config command.

Using node, you will access your environment variables using process.ENV.VARIABLE , where VARIABLE is the name of the environment / configuration variable that you are trying to access.

As a final note, you can add local environment variables in .env to the project directory (add the file to .gitignore!) ... the wizard will load them when you use foreman start or foreman run .

+8
source

if you run:

  heroku config 

toolbelt will show env variables, so you can use the env variable inside your code:

  process.env.VARIABLE 
+1
source

Source: https://habr.com/ru/post/953073/


All Articles