The Best Way to Manage your .env Files ft. Dotenv Vault
2 min read
Environment variables are extremely important to keep track of in your projects.
In your decently sized projects you may find yourself needing to either keep track of multiple environment variables for the different stages of your application - development, beta, production - or you may have some teammates who need access to your one or more environment variables.
As a solution, one of my teammate's former startup teams had everyone store their .env files in a Slack channel. However, this wasn't very convenient for them.
Whenever someone needed a different set of environment variables they would need to open up Slack, find the secrets channel and then search or scroll up to the secret they were looking for. In addition, they quickly reached the 10,000 free Slack message limit and soon past messages were wiped from existence.
You know where I'm going with this 😬
The secrets were deleted.
Or even on a smaller scale, with all of your environment variables of your personal projects in the .gitignore (I sure hope so! If not, please take this Developer Pledge with me) you decide to wipe your disk one day to save space. Oops, you just lost all of those environment variables and may be unable to re-run most of those applications.
Thankfully, from the creators of the popular dotenv node module we've all used a billion times, there's Dotenv-Vault that solves this very problem. Imagine a simple dashboard that looks like this to manage all of your keys
You can easily cycle through the different .env files for your different stages and share your dotenv-vault project with your collaborators.
Additionally, you don't even have to go to the website to go get an environment variable value. You can access these keys from your terminal with
npx dotenv-vault pull development
to pull your development environmental variables and dotenv-vault will automatically create a pre-populated .env file with all of the Key Values loaded in.
Note: If you wanted the production environment variables instead you can simply do
npx dotenv-vault pull production instead
They also come with a few additional files, .env.me which is used to identify you and .env.project which identifies from which project in Dotenv-Vault did you take the environment variables from.
Go check their site out for more! As I've mentioned before, Dotenv-Vault is from the same team that created the popular dotenv npm package with the Founder being one of the main contributors to the .env format.
I hope I helped you find a great new method for storing and sharing your environment variables with all of your projects. Happy Hacking! 🥳💻
Did you find this article valuable?
Support Kevin Xu by becoming a sponsor. Any amount is appreciated!