motdotla / dotenv

Loads environment variables from .env for nodejs projects.

Home Page:https://www.dotenvx.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable expansion only works when it matches the entire value

apm opened this issue · comments

In a bash script, it is common to see things like this:

DEPLOY_TARGET=stage
API=http://api.${DEPLOY_TARGET}.foo.com/

It looks like _processForPotentialEnvVariable does this (w/o the braces), but only if the entire value matches another env entry. I'm not sure why anyone would want to do that, but filling out the feature to replace variables within the value would be useful.

👍 This would be a nice to have, just stumbled on this issue myself

commented

I can see this concern, but I think it is too complex - especially after I've merged #42, and dug deeply in. There are edge case bugs, and now two different ways to write variables. It gets away from constraints and creatively using constraints to get to the end result you want.

For example, for your example here:

DEPLOY_TARGET=stage
API=http://api.${DEPLOY_TARGET}.foo.com/

You could instead do this:

API_URL=http://api.staging.foo.com/

Now you only have one ENV variable. Then in each environment have a different .ENV.

Managing multiple config files is more complex to me, especially if you have more than a couple. With this patch, I can have a single config file and execute from a shell script with a single env var to configure the deploy target like I do for other parts of the system written in different languages, and I can do this without specific configuration tweaks for dotenv.

So if this is a simple no to a patch that adds needed support for proper variable substitution without changing the existing functionality, okay. I'll leave my fork around as it is working fine for me @davidchase