### Directories of configurations
To load directories that contain configuration files in the options object provide locations property that is an array of directories than contain your configurations.

var gofigure =require("gofigure");

var loader =gofigure({locations :[__dirname+"/configs"]});

loader.load(function(err,config){

varPORT=config.port,HOST=config.host;

});

The order of the locations matter as it defines a precedence for files. For example suppose you have a directory of default configuration files, and on production you want to override those configuration with environment specific configurations with out changing your module or source controlled files.

Since Etcd is a centralized configuration store, the concept of a node type needs to be introduced. By default gofigure will look for NODE_TYPE and, if it is set, then it will use it. To programmatically load just the production webapp properties set, the environment to production and nodetype to webapp.

var gofigure =require("gofigure");

varETCD_CONFIG={endpoints:["127.0.0.1:4001"], root:"/appname"};

var loader =gofigure({

locations :[ETCD_CONFIG],

environment :"production",

nodetype :"webapp"

});

Type Layout

When using NODE_TYPE you will need to use the type property in your json, and Etcd. If process.env.NODE_TYPE is set, gofigure will look for the following:

In JSON

{

"production": {},

"development": {},

"type":{

"production": {},

"development": {},

}

}

Example

For the following example:

process.env.NODE_ENV="production";

process.env.NODE_TYPE="webapp";

This can be defined through configuration files JSON by doing the following:

production.json

{

"production":{

"host":"prod.mydomain.com",

"port":"80"

}

}

development.json

{

"development":{

"host":"dev.mydomain.com",

"port":"8080"

}

}

{

"type":{

"production":{

"webapp":{

"host":"prod-special.mydomain.com",

}

},

"development":{

"webapp":{

"port":"6060"

}

}

}

}

Which would generate the following configuration object.

Assume the following env NODE_ENV=production NODE_TYPE=webapp

{

"host":"prod-special.mydomain.com",

"port":"80"

}

If you changed NODE_ENV=development NODE_TYPE=webapp

{

"host":"dev.mydomain.com",

"port":"6060"

}

Using NODE_TYPE with Etcd

When using NODE_TYPE with Etcd your URI would look like the following

127.0.0.1:4001/v2/keys/<root>/type/<NODE_ENV>/<NODE_TYPE>

To load Etcd with a NODE_TYPE your code could look like the following.

Assume the following env NODE_ENV=production NODE_TYPE=webapp

var gofigure =require("gofigure");

varETCD_CONFIG={endpoints:["127.0.0.1:4001"], root:"/appname"};

gofigure would generate the following URI to retrieve the type config from Etcd.