Closed jzaynal closed 3 months ago
dotenv has never done that. you might find dotenvx useful though. it is new and has a close analog to what you are describing.
@motdotla I understand that it hasn't ever done that but do you think my expectation is reasonable? i.e. do you think it should do that? Reason I'm asking is you must've come across the need for this behaviour in the lifetime of dotenv
and now dotenvx
- I see that it's simpler to configure different environments with dotenvx
now but still doesn't just automatically use it from NODE_ENV
environment variable; I still have to specify explicitly.
If you have indeed considered it, can you explain the drawbacks of this as I'm now using a 'customised' dotenv
configuration loading that does just that and I want to be careful if there are pitfalls.
yes, i understand. it's somewhat reasonable but not given the scale of dotenv at this point. dotenv is depended on by major libraries, frameworks, and platforms. changing this would be a massive surprise and disruption.
that's why it lives in dotenvx.
This may well be a me issue as I'm not familiar with this package enough, so please let me know if that's the case.
I would expect
dotenv
to automatically pick up correct.env
file based on value ofNODE_ENV
.For example, if I have
.env
and.env.test
and doNODE_ENV=test node
, runningrequire('dotenv').config()
without specifying path explicitly I would expect it to pull values from.env.test
.If I have to specify
path: '.env.' + process.env.NODE_ENV
I'm sorry but this defeats the whole point of multi-environment configuration with the library.