Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
terrabythia opened this issue Feb 22, 2023 · 1 comment
Open

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

terrabythia opened this issue Feb 22, 2023 · 1 comment

Comments

@terrabythia
Copy link

terrabythia commented Feb 22, 2023

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
Copy link

zaq42 commented Mar 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants