read, configure and enforce a configuration file.

npm install general-hammond
48 downloads in the last month

General Hammond

Reads your cascading service config file, enforces its content, and hands it to you for immediate utilisation. You have a go.

Lieutenant General George Hammond


npm i general-Hammond

hammond([domain], [keys])

  • domain - the domain of the config to use (optional, no default) - see cascading service config for more info
  • keys - required keys in the config. see assert keys for more info. this is run after the config is parsed as a CSC.

returns a function that takes one argument, a callback. the callback is passed a single argument, the config. If the config is not found or the fails to parse, an error is thrown (it's assumed that you want the process to terminate at that point)


require('general-hammond')('api-server', ['port'])(function(config) {
  // at this point it is guaranteed that the config was found and had a `port`
  // property set under the `api server` domain.

config overrides

You can override settings in the config by specifying the GH_CONFIG_OVERRIDE environment variable. The value should be a stringified JSON object with values that override those in the config. The values are overlayed by using deep-extend.

For example, given config.json {"service": {"port": 2345, "name": "service!"}}:

export GH_CONFIG_OVERRIDE='{"service":{"port":5678}}'
node service --config config.json

The service receives this config: {"service": {"port": 5678, "name": "service!"}}

npm loves you