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

feat: set or update environment variables dynamically (#1476) #1575

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

seiwonpark
Copy link
Contributor

@seiwonpark seiwonpark commented Jan 7, 2024

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 we can get environment variables and set cache. But there's no feature for setting environment variables dynamically. This could be useful even when testing the server locally so to make it dynamically updated when reloaded.

Issue Number: #1476

What is the new behavior?

This PR adds feature for setting/updating environment variables with the method set in ConfigService. And as @nestjs/config depends of dotenv-expand to resolve interpolation, I could get hint from NOT being interpolated.

So after getting environment paths from module's config, simply can parse the environment variables as raw strings (I mean, like the option expandVariables to false). And then simply just replacing interpolated variables too.

This resolves #1476

Does this PR introduce a breaking change?

  • Yes
  • No

@carlosmesas-acciona
Copy link

When will this improvement be brought to production? I find it interesting

@seiwonpark
Copy link
Contributor Author

@kamilmysliwiec Could you review this PR? Or is there anything else that I need to do here?

@skypencil
Copy link

What is the status on this PR?

@w0aw
Copy link

w0aw commented Feb 7, 2024

if i create an api endpoint (all it does just change env variable at runtime using this.configService.set() method) will it change output of configService.get() immidiately ? or it will try to override .env file?

because in most cases in prod (when using docker/ k8s) we don't have .env file. ideal solution would be set config variables in memory in place of environment level

@kamilmysliwiec kamilmysliwiec merged commit 78cd4f2 into nestjs:master Feb 7, 2024
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

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.

Non-Reactive Behavior of NestJS ConfigService with Dynamic Environment Variable Updates
5 participants