Class: Config

Config

new Config(fsLoader, cli, options)

A utility which helps you managing to manage and organize your configuration for different environment nicely spread out over multiple files. The configuration can be broken down as follows: (By default the config utility looks for a config folder at the root of your project) ``` config/ ├── default.js ├── default │   ├── app.js │   ├── breakpoint.js │   ├── credentials.js │   ├── fear.js │   ├── karma.js │   ├── mustache.js │   ├── packages.js │   ├── paths.js │   ├── protractor.js │   └── webdriverio.js ├── development │   ├── app.js │   ├── karma.js │   ├── protractor.js │   ├── webdriverio.js │   └── webserver.js └── integrated ├── app.js ├── karma.js ├── protractor.js ├── webdriverio.js └── webserver.js ``` # Introduction In the default.js file you can require your default configuration values which resides in the default fodler. If no default.js file is present, the config utility will try to load all the default properties from the files in the folder. Using the filename as key on the object. Default the config utility will fallback to the devlopment environment, but this can be overriden be providing --env args to a commandline utility or by setting the NODE_ENV variable to a different environment. ## Getting a value A configuration value can be requested by providing the correct key to the get function: ```js var karma = config.get('karma'); ``` The above function will return the full configuration object provided by the default/karma.js file overriden by (development/integrated)/karma.js. It's also possible to get a specific config value from the karma file. If the karma.js file contains the following code: ```js module.exports = { server : '127.0.0.1' } ``` Calling the get function with the following keys will return the coresponding value in the karma.js file: ```js var server = config.get('karma.server'); ``` ## Templating the return value It's possible to template a key using the handlebars syntax. If for example a certain path.js config file would look as follows: ```js module.exports = { css: '{{base}}/css', js: '{{base}}/javascript' } ``` Using the get syntax with a certain context object will return the templated string ```js var css = config.get('paths.css',{ base: 'app' }); // returns: 'app/css' var paths = config.get('paths') // returns: { css: 'app/css', js: 'app/javascript' } ``` ## Changing the target It is also possible to provide a target string as second or third parameter. This will switch the target folder where configuration files get loaded from: Given the following config folder structure: ``` ├── buser ├── default │   └── config.js │   ├── cardTypes.js │   ├── checkoutHeader.js │   ├── config.js │   ├── content.js │   ├── countries.js │   ├── espots.js │   ├── featureSwitch.js │   ├── globalHeader.js │   ├── instructions.js │   ├── labels.js │   ├── miscellaneous.js │   ├── pageContent.js │   ├── userLogon.js │   └── userRegistration.js ├── defaults.js ├── mobileapp │   └── config.js └── tsop ├── checkoutHeader.js ├── config.js └── labels.js ``` You can provide a different target via: ``` var mobile = config.get('config', 'mobile') //returns: config object in mobile folder var tsop = config.get('config', { base : 'tmp' }, 'tsop) //returns: config object in mobile folder while templating the result ``` ## Options The config utility can be configured using a configurations object. The default values are as follows: ```json { "root": "config", //Root folder where the utility will look for configuration files "delimeters": /{{([\s\S]+?)}}/g, //Regex used as matching algorith for templating values "target": "development", //The default target folder "debug": false //Determines if the utility logs verbose information } ``` These defaults can be cahnged as follows: ```js var config = require('fear-core').config({ root: 'mocks/channel', //changes the root folder delimeters: /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g // Changes templating algorithm to '${value}' }) ``` ## Debugging It is possible to let the config utility log debug statements by setting the NODE_DEBUG environment variable to config. ``` NODE_DEBUG=config gulp ... ``` Or by setting debug to true in the options object. ```js var config = require('fear-core').config({ debug: true }); ```
Parameters:
Name Type Description
fsLoader object
cli object
options object
Properties
Name Type Description
root string The root config folder, defaults to config
delimeters regex Regex used for the templating algorithm, defaults to handlebars matching
Source:
Throws:
Will throw an error when there is no default.js or default folder in the root folder

Methods

env() → {string}

Source:
Returns:
Representing the current environment, taking in to account the node environment, cli arguments, defaults to development
Type
string

path(type) → {string}

Parameters:
Name Type Description
type string
Source:
Returns:
Filepath to the requested config file
Type
string