Search…
Config
Simplified configuration and local secrets storage.
1
const config = require('config')
Copied!
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.
An organization can store around 256k of config data.
There are no access controls surrounding config data in-script.

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()

1
const should = require('should'),
2
config = require('config')
3
4
// set a top-level secret
5
config.set('secret', {foo: 'bar'})
6
7
// set a pathed value
8
config.set('secret.foo', 'baz')
9
10
// set a path object
11
config.set('secret.cake', {eat: 'it', too: 'yes!'})
12
13
should.equal(config.get('secret.foo'), 'baz')
14
should.equal(config.get('secret.cake.too'), 'yes!')
Copied!

Using convenience methods

The config module may also be called as a function for getting and setting values.
1
const config = require('config')
2
3
// set a top-level secret
4
config('secret', {foo: 'bar'})
5
6
// set a pathed value
7
config('secret.foo', 'baz')
8
9
// set a path object
10
config('secret.cake', {eat: 'it', too: 'yes!'})
11
12
should.equal(config('secret.foo'), 'baz')
13
should.equal(config('secret.cake.too'), 'yes!')
Copied!
Last modified 2mo ago