dotenv-org / dotenv-vault-core

DEPRECATED: Use motdotla/dotenv which added support for .env.vault May 30, 2023.
https://github.com/motdotla/dotenv
9 stars 4 forks source link

Feature: optionally save to .env file after decryption #9

Open terrabythia opened 1 year ago

terrabythia commented 1 year ago

When adding node -r dotenv-vault-core/config before another script as in the documentation, in some cases you may want to be able to not (only) mutate process.env and adding the environment variables from the vault to it, but (also) saving the resulting .env file to the current working directory.

This is currently something I'm encountering in a specific case where I cannot run node -r dotenv-vault-core/config right before starting my server (because of server limitations), so I want to save the decrypted vault to /.env when running npm run build.

As a proof of concept I have forked this project and implemented something myself (here, see changes by checking the commit here), but I'm not sure if this is a good solution. Also there might be some reason to not do this. The complete build script would then look like this: DOTENV_SAVE=1 node -r dotenv-vault-core/config ./node_modules/.bin/next build.

Would something be like this a possible enhancement of this package or are there some reasons not to do this?

zaq42 commented 1 year ago

I was looking for documentation on how to do this.

Here's the solution I've implemented: npx dotenv-vault decrypt $DOTENV_KEY > .env

This will, of course, overwrite any existing .env so use it carefully.