rduk-configuration
v1.2.0
Published
Manage configuration in your Node.js app
Downloads
23
Readme
RDUK - configuration
Manage your Node.js app configuration
Installation
npm install rduk-configuration --save --save-exact
Naming
Add the configuration file at the root of your project. You have to name it according to the argument passed to the factory.
var configuration = require('rduk-configuration');
var myConfig;
/* config.yml */
myConfig = configuration();
/* config.dev.yml */
myConfig = configuration('dev');
/* config.prod.yml */
myConfig = configuration('prod');
Note:
If you set NODE_ENV
, you can access the configuration according to it
myConfig = configuration.load(); //will load config.dev.yml if NODE_ENV === dev
Note:
If you prefer put your config file within another folder, you can do so by adding
in the package.json
of your solution a rduk configuration section.
# example of package.json
{
...
"rduk": {
"config": {
"path": "path/to/config"
}
}
}
Reference
Configuration
Configuration.settings
Get the SettingsSection of the config file
yaml:
settings:
facebook:
appId: APP_ID
appSecret: APP_SECRET
usage:
var fbSettings = myConfig.settings.get('facebook');
console.log(fbSettings.appId); //will output APP_ID
console.log(fbSettings.appSecret); //will output APP_SECRET
Configuration.connections
Get the ConnectionsSection of the config file
yaml:
connections:
-
name: con1
host: localhost
user: db1_user
password: 123456
database: db1
-
name: con2
host: localhost
user: db2_user
password: 123456
database: db2
-
name: mapbox
token: my_mapbox_token
-
name: gmap
token: my_gmap_token
usage:
var con1 = myConfig.connections.get('con1');
var con2 = myConfig.connections.get('con2');
console.log(myConfig.connections.get() === myConfig.connections.get('con1')); //will output true
Configuration.getSection(name, type)
Get the specified section
yaml:
map
default: mapbox
providers:
-
name: mapbox
type: MapBoxProvider
connection: mapbox
-
name: gmap
type: GoogleMapProvider
connection: gmap
section:
var MapSection = function(section) {
/* ... */
};
usage:
var map = myConfig.getSection('map', MapSection);
Note:
If no type passed to the method, get the raw section.