mozilla / node-convict

Featureful configuration management library for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Defining a configuration property as "required", without providing a default value.

redking opened this issue · comments

Hey,

Perhaps I'm misreading the docs, but there doesn't appear to be a way to define a configuration property as "required" but without a default value i.e. if the property is not found in the configuration file, then validation will fail.

This would be especially useful when working with a team of developers. As it stands, a developer could delete a config property without understanding the impact; the application might appear to function, falling back to its default value as defined in the schema, but with consequences further down the line.

If this seems useful, I can try to create a pull request.

@redking
+1 on this. I am having the same issue. Any updates on the pull request?

@sidazhang I didn't get a yes or no about whether it was appropriate for the project or not; I'll try to do a PR anyway sometime over the next couple of weeks

The philosophy was to have production values be the default values. Usually you only want to change defaults for deploy or instance (in aws speak) specific tweaks. However, you can set a default value to null and if your format doesn't accept null it will throw an error.

  • What if in production environment the configuration is taken from the environment variable and it is expected to be injected by the PaaS/etc at runtime and is not known in advance?
  • What if using a production value as a default is a bad idea (for some reasons i.e. a DB password)?
  • IMHO using default: null is not better than making default an optional field. One could argue that invalid default for a required variable is ambiguous and misleading.
  • Supporting the case explicitly allows to produce meaningful error messages.