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

Inconsistent Behavior with Default Environment Variable Values Using dotenv and dotenv-expand #125

Open
GeryDeMerciYanis opened this issue Mar 28, 2024 · 1 comment

Comments

@GeryDeMerciYanis
Copy link

Hello,

I've encountered an issue regarding the handling of default environment variable values when using dotenv in conjunction with dotenv-expand.

The goal is to access an environment variable with the option to fall back to a default value if the variable is not defined. To achieve this, my .env configuration is as follows: MY_VAR=${MY_VAR:-default-value}

Upon setting up dotenv and dotenv-expand and subsequently accessing process.env.MY_VAR, the output unexpectedly matches the literal string in the .env file: ${MY_VAR:-default-value}.

However, altering the .env file to use a non-existent variable as the key in the fallback expression: MY_VAR=${NOT_MY_VAR:-default-value}
Results in the correct behavior, yielding default-value when process.env.MY_VAR is accessed.

I've prepared a minimal reproducible example available at: CodeSandbox - Node.js Playground Forked.

Environment:

Node.js version: 20.11.0
dotenv version: 16.4.5
dotenv-expand version: 11.0.6

It appears that dotenv-expand does not process the default value syntax as expected when the variable name is the same as the one being defined. I'm looking forward to any insights or solutions regarding this issue.

Thank you.

@stvvt
Copy link

stvvt commented Jun 3, 2024

I've noticed exactly the same behaviour and proposed #126 to fix it.

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

No branches or pull requests

2 participants