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

env override #63

Closed
fundon opened this issue Apr 3, 2015 · 3 comments
Closed

env override #63

fundon opened this issue Apr 3, 2015 · 3 comments

Comments

@fundon
Copy link

fundon commented Apr 3, 2015

Below my env files:

├── .env
├── .env.test

The .env is by default.
The .env.test will override the ENV.

First load .env then load .env.test.

I think that maybe need an option for override env.

https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32-L34

Object.keys(parsedObj).forEach(function (key) {
        process.env[key] = override ? (parsedObj[key] || process.env[key]) : (process.env[key] || parsedObj[key])
})
@maxbeatty
Copy link
Contributor

@fundon since releasing v1, we no longer support multiple .env files. You can accomplish the same behavior by calling config twice but it's best to use a single .env file per environment.

# .env
ANIMAL=cat
# .env.test
ANIMAL=dog
TEST=true
assert = require('assert')
dotenv = require('dotenv')

dotenv.config({path: '.env.test'})
dotenv.config()

assert.equal(process.env.ANIMAL, 'dog')
assert(process.env.TEST)

@fundon
Copy link
Author

fundon commented Apr 4, 2015

Nice! Fix my issue. Thanks.

@whytekieran
Copy link

whytekieran commented Oct 20, 2020

@maxbeatty How is this a solution to removing multiple .env file capabilities? Lets Imagine that ANIMAL in your example is actually PORT and I want my local dev and tests to run on different PORTS how is loading to files both with PORT going to help? I can only see this causing conflicts. Issue here is still an issue far as im concerned. I am yet to hear a good reason this functionality of multiple env files was even removed, there are many other frameworks that employ it and it seems perfectly good practice to them

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