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

Multiple & recursive expand #3

Merged
merged 6 commits into from
Mar 31, 2017
Merged

Multiple & recursive expand #3

merged 6 commits into from
Mar 31, 2017

Conversation

javiacei
Copy link
Contributor

@javiacei javiacei commented Apr 4, 2016

Expand multiple variables

Now you can expand multiple variables using $ and ${}.

MONGOLAB_AUTH=$MONGOLAB_USER:${MONGOLAB_PASSWORD}

Recursive expand

MONGOLAB_USER_RECURSIVELY=${MONGOLAB_USER}:${MONGOLAB_PASSWORD}
MONGOLAB_URI_RECURSIVELY=mongodb://${MONGOLAB_USER_RECURSIVELY}@...

Multiple & recursive expand tests

Added more tests checking new functionalities.

@motdotla
Copy link
Owner

motdotla commented Jun 8, 2016

Thanks for this. I'll take a look soon.

@kashav
Copy link

kashav commented Jul 18, 2016

I needed this feature for a project I'm working on, so I've been playing around with it. It seems to be overwriting preset variables (correct me if I'm wrong, but that's a bug).

Reproduce:

# .env
NODE_ENV=production
$ NODE_ENV=development node ./index.js
// index.js
const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')

dotenv.config()
console.log(process.env.NODE_ENV) //=> development (as expected)

dotenvExpand(dotenv.config())
console.log(process.env.NODE_ENV) //=> production (??)

I've found a fix in this block:

for (var configKey in config) {
  var value = process.env[configKey] || config[configKey]
  if (value.substring(0, 2) === '\\$') {
    config[configKey] = value.substring(1)
  } else {
    config[configKey] = interpolate(value)
  }
}

The problem seems to be that config maps to the object that was returned by dotenv.config, which doesn't use the preset environment variables, rather the parsed file contents. This isn't a bug, but perhaps dotenv.config should return both the compiled and raw variables (maybe another option to choose between the two)? (cc @motdotla)

@niftylettuce
Copy link

Meh, this still isn't fixed and the readme is still outdated per #2?

@rastasheep
Copy link

Any news? please?

@eliseumds
Copy link

?

@motdotla motdotla merged commit 67b2da7 into motdotla:master Mar 31, 2017
@motdotla
Copy link
Owner

Thank you everyone for this PR and for your patience. It just merged here: #5

@motdotla
Copy link
Owner

Just published on npm as 4.0.0.

@kshvmdn 😱 you are absolutely right. I'll look into that right now.

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.

None yet

6 participants