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?
|
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
Hey all! We have noticed that passing any defined values in the
debugoption inconfigfunction will turn on debug mode.e.g. all those will activate debug logs:
The documentation mentions that
debugdefaults 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:
The only way I've made it work was by passing an undefined or null value:
I do think this happens because
options.debugis checked againstnull, but not against falsy values. Is this expected behavior?dotenv/lib/main.js
Lines 83 to 97 in 27dfd3f
I'm using Dotenv version
8.6.0