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

Using an array for config.path does not work #796

Closed
tran-simon opened this issue Jan 23, 2024 · 1 comment · Fixed by #797
Closed

Using an array for config.path does not work #796

tran-simon opened this issue Jan 23, 2024 · 1 comment · Fixed by #797

Comments

@tran-simon
Copy link
Contributor

According to the readme, the path option should accept an array

path
Default: path.resolve(process.cwd(), '.env')
By default, config will look for a file called .env in the current working directory. Pass in multiple files as an array, and they will be loaded in order. The first value set for a variable will win.
require('dotenv').config({ path: ['.env.local', '.env'] })

It does not seem to be working properly

In this snippet, process.env.TEST is undefined when using path: [".env"]

console.log("Loading with array");
require("dotenv").config({ path: [".env"] });
console.log(process.env.TEST);

console.log("Loading with path");
require("dotenv").config({ path: ".env" });

console.log(process.env.TEST);

Output:

Loading with array
undefined
Loading with path
test

SANDBOX

@motdotla
Copy link
Owner

tests should have caught this, which means a bad test. it's using mocking - always brittle. i'm rearranging the tests to confirm and then will check out your pr. thank you.

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 a pull request may close this issue.

2 participants