load-config-folder 

Load the config from folder as a plain object.
- The config file format can be registered.
- The registered file format order is the search order.
- the virtual file system can be specfied:
loadConfig.setFileSystem(fs)
fs.path = require('path.js/lib/path').path for the virtual POSIX path.
- you must set the path first before call setFileSystem.
The load-config-folder is similar to the load-config-file.
But it will load the configuration from the folder with a specified file name, you can use addConfig
to set the specified config file name(it's a basename).
Usage
import loadConfig, { FolderConfig } from 'load-config-folder'
import yaml from 'js-yaml'
import cson from 'cson'
FolderConfig.addConfig(['_config']);
FolderConfig.register(['.yaml', '.yml'], yaml.safeLoad);
FolderConfig.register('.cson', cson.parseCSONString.bind(cson));
FolderConfig.register('.json', JSON.parse);
console.log(loadConfig('./folder'));
loadConfig('./folder', function(err, result){
if (err) {
console.log('error:', err);
} else {
console.log(result);
}
})
let result = await loadConfig('./folder', true)
result = await FolderConfig.load('./folder')
result = FolderConfig.loadSync('./folder')
API
import { FolderConfig } from 'load-config-folder'
FolderConfig.setFileSystem(fs): set your favour file system. defaults to 'fs'.
- the "file system" must implement
readFile(path[, options], done) and readFileSync(path[, options])
load(dir, options, done): Asynchronously load config from dir
- return the plain object and the
$cfgPath property added if suceesful.
loadSync(dir, options): Synchronously load config from dir
- return the plain object and the
$cfgPath property added if suceesful.
License
MIT