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

Dotenv running on debug mode for any non-undefined debug option #548

Closed
n8eloy opened this issue Jun 30, 2021 · 1 comment
Closed

Dotenv running on debug mode for any non-undefined debug option #548

n8eloy opened this issue Jun 30, 2021 · 1 comment

Comments

@n8eloy
Copy link

n8eloy commented Jun 30, 2021

Hey all! We have noticed that passing any defined values in the debug option in config function will turn on debug mode.

e.g. all those will activate debug logs:

dotenv.config({ debug: true })
dotenv.config({ debug: false })
dotenv.config({ debug: 'foo' })
dotenv.config({ debug: 0 })
dotenv.config({ debug: {} })

The documentation mentions that debug defaults as false, but I didn't expect that passing false explicitly wouldn't make it work the same way.

What I'm exactly trying to accomplish is programmatically activate debug mode for a certain environment variable:

dotenv.config({ debug: process.env.NODE_ENV === 'development' })

The only way I've made it work was by passing an undefined or null value:

dotenv.config({ debug: process.env.NODE_ENV === 'development' ? true : undefined })

I do think this happens because options.debug is checked against null, but not against falsy values. Is this expected behavior?

dotenv/lib/main.js

Lines 83 to 97 in 27dfd3f

let dotenvPath = path.resolve(process.cwd(), '.env')
let encoding /*: string */ = 'utf8'
let debug = false
if (options) {
if (options.path != null) {
dotenvPath = resolveHome(options.path)
}
if (options.encoding != null) {
encoding = options.encoding
}
if (options.debug != null) {
debug = true
}
}

I'm using Dotenv version 8.6.0

@nifr
Copy link

nifr commented Sep 18, 2021

This issue is still present in 10.0.0.

@motdotla - Can I help somehow to get #550 merged and a new release tagged?

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