Hey guys, recently one of you asked a question in the MERN playlist. It was about managing environment variables, like MongoDB credentials, in a Node.js app. In the video, I extract the variables from process.env and assign easy-to-guess defaults as a fallback. The plan was to then provision a local MongoDB Docker container with those defaults, and use it for development. This way, I’d feel comfortable committing those variables to version control, since they were never intended to be used in production.

When it’s time to deploy the app, I would overwrite the defaults with the actual secrets, and rely on the service provider to store them securely. In the end, I decided to use mLab, instead of Docker, which meant that I had to now leverage config variables in a dev environment as well. Since I’d not want them exposed in source code, hard-coding those vars in config.js was no longer an option. I did some digging and thought I’d share how I got around it in this video.

Windows users, beware of trailing spaces https://github.com/remy/nodemon/issue…

#node.js

Configuring Environment Variables in Node.js
24.80 GEEK