Easily Find Missing and Different Environment Variable Values
When we are working with multiple environment and with multiple concurrent project, it’s hard to keep the track of added and changed environment variable files. Let’s say that you have 10 development environment which every environment happens to be on different projects. When one of the projects is done and get released to master, it will be synced back to each of the development branches too. And if the environment variable files are git-ignored (it should be, right?), you should update environment variable files manually in each environments.
The solution
The best way to overcome this problem would be creating an automated script that adds or modify the designated environment variable values to each of the environments. But what if our environment variable files has already messed up before we could implement this idea? For example on environment A is missing environment variable on project B, because that environment is not used for about 2 weeks or something. Is there any way to find the missing and/or modified environment variable file from “reference” environment variable file?
So I’ve written up with simple script for this with Node.js, env-diff. You can install that with downloading the latest pre-build executable for each OS here, or you can compile it yourself if you prefer too.
Usage
After downloading, extract and add the executable file to your folder that have been registered on your $PATH
, so the script will be easier to call everywhere. The script will prompting your input for current environment variable file, and “reference” environment variable file.
Then, you can type the command env-diff
on your working directory, and you will be prompted with your main env path and comparing (reference) env path. After that, you will be presented with the variables that’s missing from your main env but exists on your comparing env. You can just easily copy that to your existing env file.
Simple and Effective
env-diff
is a straightforward tool that gets the job done. It's perfect for quickly identifying missing or different environment variables, saving you time and effort.
Limitations and Future Improvements
Keep in mind that env-diff
is a basic script that only compares environment variable values. It doesn't handle variable ordering or other file structure nuances.
However, because env-diff
is open-source, you can contribute to its development and help improve its functionality.What it doesn’t do
The script is still very simple, that just do comparing the current and reference environment variable file and nothing else. Therefore, if there was some variables that are placed in the middle of the file, you should manually place that in your middle of your environment variable too if you want to do it neatly. We would like this kind of improvement to our little tools in the future. because of this project was open source, any contribution will be appreciated! 😄