Quickstart

Manage multiple environments

Manage multiple environments like .env.ci, .env.staging, and .env.production with this quickstart guide.

Create .env.production

Create a .env.production file.

.env.production

# production
HELLO="Production"
edit .env.production

Next, push .env.production to its env vault.

Push

Run the push command with the environment argument.

npx dotenv-vault push production
npx dotenv-vault push production

This securely pushes your .env.production secrets to your project vault's production environment.

Next, let's view your secrets in the UI.

Open

Run the open command to view your production environment variables in the UI.

npx dotenv-vault open production
npx dotenv-vault open production

Just like the push command, you pass an additional production environment argument to open directly to that environment's secrets.

Make a change in the UI and then pull the latest .env.production file.

Pull

npx dotenv-vault pull production
npx dotenv-vault pull production

Conclusion

Solid! You completed this quickstart guide – managing your secrets across multiple environments. I recommend learning how to load .env files in development next.


Advanced Commands

Run the help push and help pull commands to see how you can further customize these commands.

npx dotenv-vault help push
npx dotenv-vault help pull

For example, a common need is to pull production secrets to a normal .env file. You can do so with this command.

npx dotenv-vault pull production .env

Default environments

Every project comes with four default environments and their corresponding .env.ENVIRONMENT files.

  • development => .env
  • ci => .env.ci
  • staging => .env.staging
  • production => .env.production

You can push to each one by appending the environment name after push.

npx dotenv-vault push development
npx dotenv-vault push ci
npx dotenv-vault push staging
npx dotenv-vault push production

The same for pulling. Append the environment name after pull.

npx dotenv-vault pull development
npx dotenv-vault pull ci
npx dotenv-vault pull staging
npx dotenv-vault pull production

Custom filenames

You can push and pull a different filename to each one by further appending the filename after the environment argument.

npx dotenv-vault push development .env.local
npx dotenv-vault pull ci secrets.txt
npx dotenv-vault push staging any-filename
npx dotenv-vault pull production .env

DOTENV_ME flag

In some automation scenarios, you might not have a .env.me file present. In those cases you can pass the value of your DOTENV_ME credential to the cli using the --dotenvMe flag.

npx dotenv-vault pull --dotenvMe=me_1z1z1z

Big congrats! You have advanced knowledge now – when it comes to managing multiple environments and using the push and pull commands.