config

Utility module that allows the initialization and loading of an environment specific application configuration. Environments refer to strings that logically distinguish between multiple execution contexts. These could be the traditional 'dev', 'qa', and 'prod' identifiers, or could be an identifier for a specific version (when mulitple concurrent versions of an app are supported). The meaning of these environment strings are left to the end user.

The Current implementation of this module uses the rc package to load configuration, and supports configuration values in files and environment variables.

Source:
Examples

Application configuration stored in files must have the following structure:

{
   "default": {
     // Default application configuration goes here. These values will
     // be used if no environment specific values are provided
     "host": "dev.example.com",
     "log": {
       "level": "error"
     }
   },
   "dev": {
     // Overrides specific to the environment "dev" can be specified here
     "log": {
       "level": "debug"
     }
   },
   "prod": {
     // Overrides specific to the environment "prod" can be specified here
     "host": "prod.example.com"
   }
}

If environment variables are used to specify config values, they must be named as follows, assuming that the application is called "myApp". For more information, see the rc standards documentation.

export myApp_default__host='dev.example.com'
export myApp_default__log__level='info'
export myApp_dev__log__level='debug'
export myApp_prod__host='prod.example.com'

Methods

(static) configure(name, defaultsopt) → {module:config}

Source:
Configures global configuration settings, include application name, and initial default values for the configuration. This method must be invoked before any calls to getConfig() in order to ensure that configuration objects are configured correctly.

Note that invoking this method multiple times could change the reference to the config object returned via a call to the getConfig() method.

Parameters:
Name Type Attributes Default Description
name String The application name to use when loading up the configuration data. See rc standards for more information on the naming and placement of application configuration files.
defaults Object <optional>
{} The default configuration properties to initialize the config with.
Returns:
A reference to the current module, allowing for chaining of method calls.
Type
module:config

(static) getApplicationScope() → {String}

Source:
Returns the current default scope for the application. This represents the default scope value that will be used in calls to getConfig(). If not explicitly overridden, this method will always return "default".
Returns:
The default scope that the config object will use.
Type
String

(static) getConfig(scopeopt) → {AppConfig}

Source:
Returns a configuration object that is scoped to a specific environment. This configuration object will return default application configuration properties, overridden by environment speicific values.
Parameters:
Name Type Attributes Default Description
scope String <optional>
<default scope> The name of the environment for which the application configuration object will be returned. If omitted, this value will be defaulted to the environment set by invoking setAppScope(). If this method was never invoked, the default scope is "default".
Returns:
A configuration object that can be used to query for configuration parameters.
Type
AppConfig

(static) setApplicationScope(scope) → {module:config}

Source:
Sets the scope for the application. This value will be used as the default arg for getConfig(). If this method is never invoked, the value of the default scope will be "default".
Parameters:
Name Type Description
scope String The default scope to assign to the config.
Returns:
A reference to the current module, allowing for chaining of method calls.
Type
module:config