A very simple configuration handler in the tradition of nconf
.
$ npm install mumba-config
import {Config} from "mumba-config";
let config = new Config({
db: {
user: 'user',
pass: 'password'
}
});
config.get(); // { db: { user: 'user', pass: 'password' } }
config.get('db'); // { user: 'user', pass: 'password' }
config.get('db:user'); // 'user'
config.get('db:pass'); // 'password'
config.set('log:level', 'silly');
Loading a file or directory
import {Config, FileLoader, DirectoryLoader} from "mumba-config";
let config = new Config();
config.registerLoader(new FileLoader())
.registerLoader(new DirectoryLoader());
config.load([{
name: 'file',
filePath: '/path/to/file.json'
},
{
name: 'directory',
dirPath: 'path/to/dir',
exclude: 'local\.js'
}])
.then(() => {
console.log(config.get())
})
.catch(console.error);
Loads a JavaScript or JSON configuration file.
Parameter | Type | Description |
---|---|---|
type |
string |
Required Must be set to file . |
filePath |
string |
Required The full path to the configuration file to load. |
Loads a directory of JavaScript or JSON files.
Parameter | Type | Description |
---|---|---|
type |
string |
Required Must be set to file . |
dirPath |
string |
Required The full path to directory containing the configuration files. |
exclude |
string |
An optional regular expression for files to exclude from the directory. |
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
The original author of Mumba Config is Andrew Eddie.
© 2016 Mumba Pty Ltd. All rights reserved.