-
-
Notifications
You must be signed in to change notification settings - Fork 837
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
Added overwrite option #72
Conversation
We'll take a look soon @jordansexton. In the meantime, can you fix line 41 of lib/main.js to fit the @feross standard style. Currently this is failing in travis as a result of that.
|
I'm not in favor of this. Environment variables should vary by environment. If you are overwriting variables in an environment, you're misusing dotenv. |
Misusing dotenv? I don't see why the library should be opinionated about how you get variables into your environment. It's job is just to do that. If you happen to want to overwrite ones that are already there, then why should it stop you from doing so? |
For context, how I use it is with a |
All libraries are opinionated. dotenv chooses to have as simple of an interface as possible, only introducing additional configuration when necessary. Using multiple .env files is an anti-pattern because you are not distinguishing your environments. If you have values that are the same for several environments, you should reevaluate if they are indeed environmental or if you're sharing sensitive data which could lead to bigger problems (e.g. reusing your production database password in staging, having your staging environment compromised, and now having production at risk). By not having an overwrite option or reading multiple files by default, dotenv encourages a single .env file so developers don't fall into these traps. How would you use this override option? What would the implementation look like?
You could just as easily switch the two lines to accomplish the same thing without the additional option:
You can load environment variables however you like. We can maintain less code and documentation. |
Except in your example, you can't override variables that are already part of the environment merely by reversing the order of the config calls. For example, let's imagine I want to debug an error that's occurring in production on my local machine with automated tests. With this change, I can add Putting your environment variables in files at all is an antipattern according to the 12 factor guidelines. If we're going to rely on dogma, this library shouldn't exist to begin with. I submit that it exists because it's convenient and not because it's correct, and thus we should care about developer convenience and not make the end user jump through hoops or unnecessarily block usages that may not be standard. And since the readme claims this is based on Ruby's dotenv, this is standard usage there regardless. |
Thanks for offering a solution to your problem. It's not something I feel would improve this module based on the usage you've outlined. |
All libraries may be opinionated, but good tools can accommodate more than one opinion on how they should be used. While I appreciate the feedback and don't expect you to agree with me, it does seem like you'd rather not actually engage with this because it's not your preferred usage. The existing behavior is a sane default and keeps people from shooting themselves in the foot, but have you considered that with a few PRs now (#35, #55) for a feature like this, all less generally applicable than this one, it might be more than just "a solution to [my] problem"? |
@motdotla @maxbeatty I respect your opinion, and went through multiple bug reports. We're using Docker from development to production. Can you please suggest us an approach.
Hope you get the scenario. Changing the order won't help, since there is no default |
@rdsubhas I just have some brief experience with |
@maxbeatty Yes exactly, I am using docker-compose.yml's To be a bit more clear:
Right now, before starting all the tests, I'm manually loading the |
Perhaps you could have a Probably best to keep brainstorming this docker solution in their GH Issues, StackOverflow, or discuss live on IRC. Good luck! |
@maxbeatty nice suggestion, just that having a separate yml and env_file means I have to copy and paste all environment variables from dev to test, and just change the ones that differ. I was kinda more looking at test-only overrides. I have a temporary alternative in loading the env variables manually after parsing, will keep brainstorming in other place as well. Thanks for the help! |
I added an option to overwrite the variables. This has been useful to me for a number of reasons, like overriding
NODE_ENV
for staging environments on the fly to test, loading multiple env files in succession, etc. In the process of adding a new test for it, I discovered that the stubs inbeforeEach
weren't setting theTEST
env properly (they were looking attest
instead), so the test fordoes not write over keys already in process.env
was guaranteed to succeed, but not because the code was running correctly -- it was just assigningprocess.env.test
rather thanprocess.env.TEST
. This patch also fixes that.