-
Notifications
You must be signed in to change notification settings - Fork 431
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
Dotenv overrides existing env variables #5
Comments
@jsantos17 thanks for reporting this.
I think it's primarily because it was un-noticed and is an undocumented behaviour. I'm happy to make a new release, with the new behaviour in place. Want to submit a PR? The new behaviour is arguable to have it or not have it. But I would suggest to go with what's happening elsewhere and be consistent with libraries. |
There should also be an configuration to toggle either of the behaviour while loading the E.g. https://github.com/stackbuilders/dotenv-hs#configuration |
@theskumar I think I can work on a PR over the weekend. Thanks for the quick response 👍 |
@jsantos17 The current behavior does not override existing entries in |
@gsong I believe, what @jsantos17 meant is that if |
@theskumar In that case, the system environment variable takes precedence, according to the code and my observed behavior. I think that's the correct behavior, with potentially a feature enhancement to override as necessary, right? |
@gsong the key/value defined in the dotfiles takes precedence as these values are loaded later and also because you are explicitly putting those values in PS: I never required to have a conflicting variable during my development/production. But I'm not sure what kind of use cases people have around it. |
@theskumar I don't think that's the behavior though. Since the code explicitly reads Or am I misunderstanding this thread? |
@gsong I guess, I have to say you are right!!! Thanks for clarifying my miss-understandings! I'll writeup some test cases and we should be good! |
Going to have to be contrarian here: a good 12-factor application relies on defaults, which can be overwritten by system environment values, which in turn can be overwritten by explicit As such, it makes far more sense to have dotenv load in the system evironment variables, and then override each that is explicitly different in the
to get either the default value, or the system override if there is one, or the env override on either if a developer needing an explicitly different value. The reason being that env files are trivial to change, whereas setting environment variables is super hard, especially cross-platform (good luck temporarily setting some env vars in Windows, for instance) |
NodeJS version DO NOT override existing variables: |
Hi, |
Support for overriding system variable is available in 0.7.0 now. Thanks Nimrod :) |
Common behavior of dotenv packages is not overriding existing environment variables.
.env
by default.env
should not write over existing variables or at least provide an option to avoid overriding:Examples of the common behavior
Go: https://github.com/joho/godotenv/blob/master/godotenv_test.go#L122
Ruby: https://github.com/bkeepers/dotenv/blob/master/spec/dotenv/environment_spec.rb#L25
Haskell: https://github.com/stackbuilders/dotenv-hs/blob/master/spec/Configuration/DotenvSpec.hs#L21
Clojure: https://github.com/tpope/lein-dotenv/blob/master/test/lein_dotenv/plugin_test.clj#L11
Why does this implementation work differently?
The text was updated successfully, but these errors were encountered: