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

Should environment specific values override globals? #5

Closed
jessefulton opened this issue Oct 31, 2013 · 6 comments
Closed

Should environment specific values override globals? #5

jessefulton opened this issue Oct 31, 2013 · 6 comments

Comments

@jessefulton
Copy link
Contributor

I haven't dug too deep into the ruby version, but based on the rails implementation shouldn't environment-specific environments override the global? ie., values in .env.development should override the same variables (if defined) that are in the main .env file.

Currently, the opposite is true. Changing this is just a matter of reversing the order of the calls in the main load() method.

Is this a bug, or am I expecting it to work backwards?

@jessefulton
Copy link
Contributor Author

Just to clarify, my use case is that I'm using Foreman to run my node site and its dependencies. Foreman loads in .env files, so it's convenient to be able to set overrides for a testing environment in a .env.test file and have it inherit from the main .env settings.

@maxbeatty
Copy link
Contributor

Why wouldn't you set your overrides directly in .env?

I'm trying to understand the need for the different environment files (see other comment)

@motdotla
Copy link
Owner

This should be looked at as inspiration: bkeepers/dotenv#4

@jessefulton
Copy link
Contributor Author

Maybe I'm misunderstanding, but it seems like that thread is implying it works as I've suggested. They're saying that env variables cannot be overwritten if they already exist. And since it loads the environment specific file first, then when a value is present in both .env and .env.development, the value in .env.development would take precedence. It's a different way of phrasing it, but would accomplish the same thing.

I think what's missing from this project is that the environment variables can be overwritten. I'd imagine adding something like this in main.js would work?

process.env[key] = process.env[key] ? process.env[key] : value;

(edit: you'd actually want to explicitly check for undefined to account for falsy values, but you get the idea)

@motdotla
Copy link
Owner

motdotla commented Nov 3, 2013

Interesting. Yeah, I am reading it the other way. I'm going to test out ruby's dotenv and see how it is doing that. I'll match the library up to however it's working in the ruby version.

motdotla added a commit that referenced this issue Nov 3, 2013
@motdotla
Copy link
Owner

motdotla commented Nov 3, 2013

@jessefulton you were correct. version 0.1.0 has the behavior you are expecting now.

@motdotla motdotla closed this as completed Nov 3, 2013
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

3 participants