Skip to content

src: add --env-file-if-exists flag#53060

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
BoscoDomingo:feature/optional-env-file-argument
Sep 16, 2024
Merged

src: add --env-file-if-exists flag#53060
nodejs-github-bot merged 1 commit intonodejs:mainfrom
BoscoDomingo:feature/optional-env-file-argument

Conversation

@BoscoDomingo
Copy link
Contributor

@BoscoDomingo BoscoDomingo commented May 19, 2024

Add a new flag, --env-file-if-exists that allows loading .env files without throwing an error if they don't exist.

Achieved by returning an env_file_data struct instead of just the paths of the .env files. This tells the loader if the file itself is required or not, thus allowing to not throw an error if the file doesn't exist and is optional, without breaking existing behaviours with --env-file (we could maybe show a warning if an optional file is missing?).

Usage:

node --env-file A.env --env-file-if-exists B.env

If B.env exists, it will load its environment variables and overwrite those that conflict with A.env. If it doesn't, node will continue as normal.

Fixes: #50993
Refs: #51451

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. dotenv Issues and PRs related to .env file parsing lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --env-file-if-exists