Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of reading configuration values favours environment variables over custom configuration #1822

Open
3 of 4 tasks
sorooshme opened this issue Sep 23, 2024 · 0 comments
Open
3 of 4 tasks
Labels
bug Something isn't working

Comments

@sorooshme
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Imagine the following custom configuration:

process.env.CUSTOM_FEATURE_ENABLED = 'true'; // environment variables are always a string - loaded by k8s for example

export default () => ({
  "CUSTOM_FEATURE_ENABLED": process.env.CUSTOM_FEATURE_ENABLED === 'true'
})

Loading this into the ConfigModule and then reading the value using:

const value = configService.get('CUSTOM_FEATURE_ENABLED');`

leads to the value being string true instead of a boolean value, this happens because the ConfigService tries to load the value from the environment variables first (instead of preferring to load from the custom configuration)

Minimum reproduction code

sorooshme#1

Steps to reproduce

The PR includes tests that confirm this (unexpected) behaviour.

Expected behavior

I expect the environment variables to be checked last, not first.

Let me know if you think otherwise.

Package version

3.2.3

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Not using the same name as the config property name and the environment variable name could solve this, cause there won't be a clash.

But still, I believe this is a major issue, we should let the developer choose whatever property name they want, without the knowledge of their runtime environment variables.

I imagine the PR for this will be fairly straight forward (just changing the order of read), so I can submit it once we agree that this needs attention.

@sorooshme sorooshme added the bug Something isn't working label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant