Closed timhettler closed 9 months ago
Hi @timhettler,
Thanks for the suggestion.
Interesting… So, as far as I understand, the difference is that .env.local
has priority over .env.${NODE_ENV}
. It definitely makes some kind of sense.
I'm thinking about the name and variations of the option and considering "order" or "priority" cannot imagine anything obvious/easy to read. The only readable solution I could imagine so far is providing a list of files
in the order you'd like them to be loaded. It would look something like this:
require('dotenv-flow').config({
files: [
'.env',
`.env.${process.env.NODE_ENV}`,
'.env.local',
`.env.${process.env.NODE_ENV}.local`,
]
});
(shell/predefined variables will always have a priority over those defined in env files)
Any other ideas?
This solution definitely gives the user the most control! Alternatively, as a convenience, you could provide something like sortingStyle?: 'nextjs' | 'default'
config option. I'm not aware if there are other frameworks that use a different convention.
Heya @timhettler 🙌
Here is a PR: #87. Please take a look when you have a free moment. If everything is good I'll release it as v4.1.0
.
Thank you for this change!
The file priority for this project does not match the convention in Next.js
process.env
.env.$(NODE_ENV).local
.env.local (Not checked when NODE_ENV is test.)
.env.$(NODE_ENV)
.env
(See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order)
It would be great to have an option to match this convention.