'Using MongoDB connection string in a Github repo
This might be kind of a weird question, but I have a full-stack project that I am using MongoDB for the database. I am about to put it on a local Github repository. Obviously in the connection string, I have a username & password which I would rather not make public. Does anyone know of a more secure way of doing this?
The whole purpose of this project is to add it to my portfolio, so future employers can see it and potentially try it out. Which means I want it to be as hassle free as possible. I've never done this before so I don't even know if someone who wants to use it would have to set up their own Mongo database just to get it to work properly or if my database can be use for everybody who would potentially want to try it out.
I don't really know what I am doing here.
Solution 1:[1]
You can use mongodb://localhost as the default connection string, committing this to the repository and using something like dotenv to override the connection string in your application at runtime.
Solution 2:[2]
You need to setup environments files and add them in gitignore file. Then use dotenv for reading the values inside the file.
Article for step by step guide: https://www.coderrocketfuel.com/article/store-mongodb-credentials-as-environment-variables-in-nodejs
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | D. SM |
| Solution 2 | FBC |
