This is a simple Node-based script that makes an up-to-date .env.example file from your project's .env file when used. It will either create a new .env.example file or overwrite your existing .env.example file with the latest version of your .env file, copying only the variables without any values, as well as any comments.
Example .env file
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=12345
# This is a comment
Resulting .env.example file using env-eg command
DB_HOST=
DB_USER=
DB_PASSWORD=
# This is a comment
This script can be set as a CLI by copying, moving, or adding a symlink of the script to a directory in your $PATH (see instructions below). You can then use the command
$ env-eg [custom-name]to generate a .env.example file, or an example file for a custom-named .env file. For example, calling env-eg production.env will create a production.env.example file.
NB: These installation instructions work on Mac OS. The instructions may work in similar fashion on Linux or Windows, or you may need to use equivalent commands. You also need to have Node.js installed for this script to work.
You can either move/copy this file to a directory in your $PATH (see step 2), or add a symbolic link (symlink) of this file to a directory in your $PATH (see step 3). Adding it as a symlink is recommended if you would like to keep the script up-to-date with any changes to this repository.
- Clone this repository to your system.
- If using this script as a CLI by moving/copying the script:
- Check which directories are in your
$PATHusingecho $PATH | tr \: \\n. - In your terminal, in the root folder for the script, move or copy the script to one of the directories in your
$PATHusingmv env-eg /path/to/directoryorcp env-eg /path/to/directory. For example, if you'd like to move this to/usr/local/bin, type the commandmv env-eg usr/local/bin.
- Check which directories are in your
- If using this script as a CLI by making a symlink of the script:
- Find the path for the root folder of the
env-egfile usingpwdin your terminal. - Enter the command
ln -s /path/to/env-eg /path/to/directory. For example, if you'd like to add a symlink of this file located in~/make-example-envto/usr/local/bin, type the commandln -s ~/make-example-env/env-eg /usr/local/bin.
- Find the path for the root folder of the
You should now be able to call env-eg in the root folder of any project where a .env file exists. Enjoy!
Please see this gist to learn how you can automate creating/ updating your .env.example file with your server running through nodemon.