Config

Simplified configuration and local secrets storage.

const config = require('config')

The config module serves as general purpose key/value storage for organization configuration and secrets.

Configuration keys can be exported and imported using the developer tools when they are named using namespace rules (c_ or namespace__) to keep local secrets out of version control. Config keys can also be included in Deployments.

module Config

keys()

Returns the list of configuration keys.

Returns

  • { String[] } An array of configuration keys.

get(key)

Returns the value for a configuration key. The key can also be an object property path.

Arguments

  • key { String } The key name or object property path.

Returns

  • { * } The key value.

set(key, val)

Set the value for a configuration key.

Arguments

  • key { String } The key name or object property path.

  • val { * = null } The value. Overwrites the value at key. If null, unsets the value at key.

Returns

  • { * } The key value.

Examples

Using get() and set()

const should = require('should'),
      config = require('config')

// set a top-level secret
config.set('secret', {foo: 'bar'})

// set a pathed value
config.set('secret.foo', 'baz')

// set a path object
config.set('secret.cake', {eat: 'it', too: 'yes!'})

should.equal(config.get('secret.foo'), 'baz')
should.equal(config.get('secret.cake.too'), 'yes!')

Using convenience methods

The config module may also be called as a function for getting and setting values.

const config = require('config')

// set a top-level secret
config('secret', {foo: 'bar'})

// set a pathed value
config('secret.foo', 'baz')

// set a path object
config('secret.cake', {eat: 'it', too: 'yes!'})

should.equal(config('secret.foo'), 'baz')
should.equal(config('secret.cake.too'), 'yes!')

Last updated

Was this helpful?