Skip to content

src: support override option in process.loadEnvFile - #63197

Closed
Han5991 wants to merge 2 commits into
nodejs:mainfrom
Han5991:feat/process-loadenvfile-override
Closed

src: support override option in process.loadEnvFile#63197
Han5991 wants to merge 2 commits into
nodejs:mainfrom
Han5991:feat/process-loadenvfile-override

Conversation

@Han5991

Copy link
Copy Markdown
Contributor

Adds an opt-in override option to process.loadEnvFile() and a matching --env-file-override-local CLI flag, so callers can swap env-file contexts within one process lifetime (integration tests, monorepo configs).

process.loadEnvFile('.env.test',{override: true});
node --env-file=.env --env-file-override-local index.js

Default behavior — existing env vars take precedence — is unchanged (the contract from #49424).

Based on prior work in #52531 (rebased onto current main, with Maybe<void> return type, lazy getValidatedPath, options-only overload detection, 7 new test cases).

Refs: #63027
Refs: #52531

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels May 8, 2026
@codecov

codecovBot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.24%. Comparing base (bbf51ad) to head (8443aa9).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #63197 +/- ##
==========================================
+ Coverage 90.03% 90.24% +0.20% 
==========================================
Files 713 714 +1 Lines 224950 225728 +778 Branches 42532 43512 +980 ==========================================
+ Hits 202542 203707 +1165 + Misses 14175 13829 -346 + Partials 8233 8192 -41 
Files with missing linesCoverage Δ
lib/internal/process/per_thread.js99.47% <100.00%> (-0.35%)⬇️
src/node.cc76.19% <100.00%> (+0.03%)⬆️
src/node_dotenv.cc84.72% <100.00%> (ø)
src/node_dotenv.h100.00% <ø> (ø)
src/node_options.cc80.73% <100.00%> (+4.12%)⬆️
src/node_options.h97.90% <100.00%> (-0.09%)⬇️
src/node_process_methods.cc88.55% <100.00%> (+0.02%)⬆️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Han5991and others added 2 commits May 9, 2026 08:09
Add an opt-in `override` option to `process.loadEnvFile()` and a
matching `--env-file-override-local` CLI flag, allowing values from
`.env` files to replace existing variables in `process.env`.
By default, existing environment variables continue to take
precedence; callers must opt in explicitly. This lets a single
process swap env-file contexts at runtime (integration tests,
monorepo configurations) without manually parsing files via
`util.parseEnv()`.
Co-authored-by: Ilyas Shabi <ilyasshabi94@gmail.com>
Signed-off-by: sangwook <rewq5991@gmail.com>
Signed-off-by: sangwook <rewq5991@gmail.com>
@Han5991
Han5991force-pushed the feat/process-loadenvfile-override branch from c298987 to 8443aa9CompareMay 8, 2026 23:10

@anonriganonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm -1. This is just additional complexity with an extremely narrow use case.

@Han5991

Copy link
Copy Markdown
ContributorAuthor

I'm -1. This is just additional complexity with an extremely narrow use case.

@anonrig

Thanks for the review — quick clarification: is the concern the CLI
flag, or the JS option itself?

I can drop --env-file-override-local and keep only the JS option if
that helps. --env-file-if-exists is already CLI-only, so the area
isn't strictly symmetric anyway.

@Han5991Han5991 closed this May 12, 2026
@Han5991
Han5991 deleted the feat/process-loadenvfile-override branch May 12, 2026 00:38
@Han5991
Han5991 restored the feat/process-loadenvfile-override branch May 12, 2026 00:38
@Han5991Han5991 reopened this May 12, 2026
@Han5991Han5991 closed this Jun 20, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Han5991@nodejs-github-bot@anonrig