The docs are clear that defaults must be supplied and, although the specifics could be improved (#254), not supplying a default value usually errors out.
However, if undefined is given for a default value and the environment variable is also undefined, the format function is never called. This results in bugs like this...
var convict = require("convict");
var config = convict({
something: {
format: (val) => {
if (typeof val === 'undefined' || val === null || val === '') {
throw new Error('must be a non-empty string');
}
},
default: undefined,
env: "SOMETHING",
},
});
config.validate({ allowed: 'strict' });
// If the `SOMETHING` env var isn't set, this will return `undefined` rather than erroring
// The format() function is never called
config.get('something');
Tested on 4.4.1, see RunKit
The docs are clear that defaults must be supplied and, although the specifics could be improved (#254), not supplying a
defaultvalue usually errors out.However, if
undefinedis given for a default value and the environment variable is alsoundefined, the format function is never called. This results in bugs like this...Tested on
4.4.1, see RunKit