DEV Community

Discussion on: How to connect to MongoDB Atlas using Node.js

Collapse
sdutta099 profile image
sdutta099

Is it a good practice to provide mongo admin password in app.js ? as if i push the code to git it might give warning . Btw i am new to node js. if not then what is best way to provide the password of admin in mongo url ?

Collapse
dalalrohit profile image
Rohit Dalal Author

you can pass the credentials via environment variables and make sure you don't push that to git. something like is used in production

const url="..<process.env.USERNAME>&<process.env.PASSWORD>";
Enter fullscreen mode Exit fullscreen mode

added this just for demo purpose ;)

Collapse
sdutta099 profile image
sdutta099

thanks a lot for the reply yes i tried using above step only