I am started learn NodeJS and Mongodb and now I want to upload my project on GitHub, but don`t know how to hide link for connect to database. And should it be done?
mongoose.connect('mongodb srv://howToHideThisInfo?:[email protected]/database?retryWrites=true&w=majority')
CodePudding user response:
You can put the URI in a file and then add that file to .gitignore
and you can use process.env
variables, more on them here Process.env. You can pass the variables when starting the node app as USER_ID=239482 USER_KEY=foobar node app.js
and update the code where you want to use them as process.env.USER_ID
. So your URI code would look like so:
'mongodb srv://' process.env.NAME ':' process.env.PASSWORD '@cluster0.ta9wa.mongodb.net/database?retryWrites=true&w=majority'