You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
whenprocess.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.5dotenv-expand
version: 11.0.6It 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.
The text was updated successfully, but these errors were encountered: