Use dotenv-vault to manage your environment variables across multiple environments - like production and staging.
Open terminal, enter your project’s root directory (where your .env.vault file is), and run dotenv-vault open.
$ npx dotenv-vault open
FYI: Not a developer? You can navigate to this page by visiting ui.dotenv.org.
Click the environment dropdown button labeled ‘development’ and then click ‘production’.
Click the edit icon next to the environment variable you want to edit.
FYI: You’ll notice that your production environment variable names are already setup but with blank values. This is by design. Each time you add an environment variable to your .env file it gets copied over to your other environments.
Enter a value and click ‘Save changes’.
Return to terminal and run dotenv-vault pull production.
$ npx dotenv-vault pull production
remote: Securely pulling production... done
remote: Securely pulled production (.env.production)
Run ls -al to view it.
$ ls -al
Jul 28 17:54 .
Jul 27 13:46 ..
Jul 27 14:51 .env
Jul 27 14:51 .env.me
Jul 28 18:09 .env.vault
Jul 28 18:09 .env.production
Jul 28 17:54 .gitignore
...
Prefer to manage your non-development environments with the cli? Edit .env.production and run dotenv-vault push production.
$ npx dotenv-vault push production
remote: Securely pushing production (.env.production)... done
remote: Securely pushed production (.env.production)
That’s it! Thanks for using dotenv-vault with multiple environments.