Skip to content

feat(config): add override option to ConfigModule#2266

Open
AlexNguetcha wants to merge 1 commit intonestjs:masterfrom
AlexNguetcha:feat/config-dotenv-override
Open

feat(config): add override option to ConfigModule#2266
AlexNguetcha wants to merge 1 commit intonestjs:masterfrom
AlexNguetcha:feat/config-dotenv-override

Conversation

@AlexNguetcha
Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Currently, @nestjs/config does not allow environment variables in a .env file to override variables already defined in process.env. This is because the internal merging logic prioritizes process.env and filters out existing keys during the assignment phase.

Issue Number: #2261

What is the new behavior?

This PR introduces an override property to ConfigModuleOptions. When set to true:

  1. The internal config object will prioritize values from the .env file over process.env.

  2. The assignVariablesToProcess method will overwrite existing keys in process.env with the values from the loaded configuration.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I have added an E2E test suite in tests/e2e/override-env.spec.ts to verify both the override functionality and the preservation of the default behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant