Easily Find Missing and Different Environment Variable Values

Faldy Ikhwan Fadila
ITMI Engineering
Published in
2 min readSep 4, 2020

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.

Figure 1. Running the Script

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! :)

--

--