Skip to main content

Fields

Schema fields define configurable properties for your application.

The idea is simple: once you have specified a configurable field using the schema, you should be able to trust it, and treat any incorrect data received as a programming error rather than a user-input error.

Given this field definition...

schema.field('port', { 
type: 'number',
default: 3000,
description: 'Server port',
validator: {'$and': ['$positive', '$integer']}
})

...this application will receive a positive integer, either 3000, or whatever positive integer was provided by the user. Any incorrect configuration will be rejected early.

Because Javascript tends to be a rather "squishy" language, the distinction between a programming error and a user input error is often blurred, but there are significant benefits to enforcing clean contracts between systems and avoiding hiding bugs under mountains of redundant type casting and error checking.

See the API documentation for ConfigurationSchema for information on defining fields.