You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a follow-up of dotenv support pr to track the development process, and answer some questions that require a general discussion for making the decision to implement them.
Todos:
Precisely define the syntax of .env files, and consider a better format not based on ini
I vote "throw on non-existing env file" and "throw on multiple --env-file parameters" since those are easy to change later and lets us land without waiting for a decision on both.
Reacted by Moshe Atlow, Chemi Atlow and Bosco Domingo
Should we merge NODE_OPTIONS if both environment variable and .env version exist?
The usual practice (of environment variable precedence ordering) is command line overriding stored setting in files. That way, the end user who runs the code has the last say on the settings.
Should we support multiple --env-file through the CLI?
Yes. This will help co-existence of application and its dependencies with their own env definitions.
Should we add a programmatic API?
Yes. This will help embedded use cases where node.js is not started through the regular launcher with regular command line parsing sequences.
Should we throw if .env file does not exist?
Yes. This will help the feature function to be deterministic.
Yes. This will help embedded use cases where node.js is not started through the regular launcher with regular command line parsing sequences.
I assume that this refers to a C++ API for embedders. This might be useful if the API can be used before any of Node.js or any of its dependencies are initialized. Otherwise, embedders will run into the same problem as we did with NODE_OPTIONS.
I assume that this refers to a C++ API for embedders.
Yes, I meant that.
This might be useful if the API can be used before any of Node.js or any of its dependencies are initialized. Otherwise, embedders will run into the same problem as we did with NODE_OPTIONS.
can you please elaborate on the problem we did with NODE_OPTIONS? sorry, I am not up-to-date with that.
What I mean is that environment variables that affect Node.js, its dependenices, the embedding application, or the embedder's dependencies must be set before the respective component attempts to use it. In many cases, that means before initialization of the respective component.
(On the other hand, reading environment variables from a file is simple enough, so if an application doesn't use the Node.js CLI, it probably might as well implement this feature itself.)
What I mean is that environment variables that affect Node.js, its dependenices, the embedding application, or the embedder’s dependencies must be set before the respective component attempts to use it. In many cases, that means before initialization of the respective component.
Yes. As in, it doesn’t do much good to write JavaScript code like process.env.NODE_OPTIONS = '...' because by the time this JavaScript code runs, Node has already loaded and configured itself and so most (all?) of what you would set by this point is too late to have any effect.
Re merging versus overwriting, I feel somewhat strongly that we should overwrite, because this .env file support is general purpose for any environment variable and not just Node-specific ones, and we can’t know how to merge variables like DATABASE_PASSWORD or whatever. I think it would be confusing UX if Node environment variables got merged but non-Node ones didn’t. I was assuming that whatever variables were set in the environment would take precedence over ones set in a loaded file, but if others feel strongly that it should be the reverse I don’t have a strong opinion on this part.
ah ok, gotcha. then yeah i think #49148 (comment) makes sense because indeed it would get confusing figuring out which node options are mutually exclusive, which are single values, which are multiple values, etc.
From the documentation, I would have expected the PHIL_VAR variable set in the environment to always be the result. Instead, it seems that the .env file version of the PHIL_VAR variable over-rides it when it is used.
Does this need a quick documentation fix ("the value from the .env file takes precedence") or does the feature need fixing?
With #59052 now merged, does that complete the last remaining task of “Precisely define the syntax of .env files, and consider a better format not based on ini”?
Is the --env-file feature ready to move out of active development stability? I’d love to replace dotenv with it, but I’m still hesitant to rely on features that are marked as experimental.
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
Activity
benjamingr commentedon Aug 14, 2023
I vote "throw on non-existing env file" and "throw on multiple
--env-fileparameters" since those are easy to change later and lets us land without waiting for a decision on both.gireeshpunathil commentedon Aug 14, 2023
IMO:
The usual practice (of environment variable precedence ordering) is command line overriding stored setting in files. That way, the end user who runs the code has the last say on the settings.
Yes. This will help co-existence of application and its dependencies with their own env definitions.
Yes. This will help embedded use cases where node.js is not started through the regular launcher with regular command line parsing sequences.
Yes. This will help the feature function to be deterministic.
tniessen commentedon Aug 14, 2023
I assume that this refers to a C++ API for embedders. This might be useful if the API can be used before any of Node.js or any of its dependencies are initialized. Otherwise, embedders will run into the same problem as we did with
NODE_OPTIONS.gireeshpunathil commentedon Aug 14, 2023
Yes, I meant that.
can you please elaborate on the problem we did with NODE_OPTIONS? sorry, I am not up-to-date with that.
tniessen commentedon Aug 14, 2023
What I mean is that environment variables that affect Node.js, its dependenices, the embedding application, or the embedder's dependencies must be set before the respective component attempts to use it. In many cases, that means before initialization of the respective component.
(On the other hand, reading environment variables from a file is simple enough, so if an application doesn't use the Node.js CLI, it probably might as well implement this feature itself.)
GeoffreyBooth commentedon Aug 14, 2023
Yes. As in, it doesn’t do much good to write JavaScript code like
process.env.NODE_OPTIONS = '...'because by the time this JavaScript code runs, Node has already loaded and configured itself and so most (all?) of what you would set by this point is too late to have any effect.Re merging versus overwriting, I feel somewhat strongly that we should overwrite, because this
.envfile support is general purpose for any environment variable and not just Node-specific ones, and we can’t know how to merge variables likeDATABASE_PASSWORDor whatever. I think it would be confusing UX if Node environment variables got merged but non-Node ones didn’t. I was assuming that whatever variables were set in the environment would take precedence over ones set in a loaded file, but if others feel strongly that it should be the reverse I don’t have a strong opinion on this part.ljharb commentedon Aug 14, 2023
I would assume that individual variables would overwrite but that if the env has A and the file has B that the process would end up with both A and B.
anonrig commentedon Aug 14, 2023
@ljharb This is the default behavior right now, but do not merge NODE_OPTIONS.
➜ node git:(dotenv-support) cat .env TESTING_KEY=THIS_IS_VALUE ➜ node git:(dotenv-support) TESTING_KEY=OVERRIDEN ./out/Release/node -e "console.log(process.env.TESTING_KEY)" OVERRIDENljharb commentedon Aug 14, 2023
ah ok, gotcha. then yeah i think #49148 (comment) makes sense because indeed it would get confusing figuring out which node options are mutually exclusive, which are single values, which are multiple values, etc.
RomainLanz commentedon Aug 16, 2023
I was wondering, do you plan to support also something like
dotenv-vaultthat lets you encrypt your secret and decrypt it just in time.anonrig commentedon Aug 16, 2023
Not at the moment, but contributions are welcome.
philnash commentedon Aug 31, 2023
I was just seeing how this feature worked and I think that either the documentation or the feature is wrong in the 20.6.0 release.
The docs say:
But, I checked out the v20.6.0-proposal branch, built the latest executable and tried the following:
From the documentation, I would have expected the
PHIL_VARvariable set in the environment to always be the result. Instead, it seems that the.envfile version of thePHIL_VARvariable over-rides it when it is used.Does this need a quick documentation fix ("the value from the .env file takes precedence") or does the feature need fixing?
GeoffreyBooth commentedon Aug 31, 2023
The feature needs fixing. The environment should take precedence over the file.
mcollina commentedon Sep 4, 2023
I don't think so. The whole point of env files is to override the local environment.
50 remaining items
Hilzu commentedon Sep 18, 2025
With #59052 now merged, does that complete the last remaining task of “Precisely define the syntax of .env files, and consider a better format not based on ini”?
Is the
--env-filefeature ready to move out of active development stability? I’d love to replacedotenvwith it, but I’m still hesitant to rely on features that are marked as experimental.anonrig commentedon Sep 18, 2025
I think it's ready to be stable. Can you open a PR?
Hilzu commentedon Sep 18, 2025
Sure! Should be simple enough as it is only a documentation update.
GeoffreyBooth commentedon Sep 18, 2025
What about loading the file by default, without needing the flag?
doc: mark `.env` files support as stable
doc: mark `.env` files support as stable
doc: mark `.env` files support as stable
doc: mark `.env` files support as stable
arkon commentedon Jan 17, 2026
I logged a regression around the override behaviour while using
--watchin >= 24.12.0 here: #61412github-actions commentedon Jul 20, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
fernandopasik commentedon Jul 20, 2026
should #63027 be added to this umbrella ticket?