I am looking at this https://github.com/lorenwest/node-config , and it seems to do everything I need. However I am wondering if it's possible to specify multiple config files based on their categories.
Is this possible to do this?
./config
default-aws.json or aws-default.json
production-aws.json or aws-production.json
db-default.json
db-production.json
etc..
so the config files can be smaller? I know we could make a giant config that has all of those required in different sections. eg
{
"aws": {
"kinesis": "my-stream"
....
},
"db": {
"host": "my-host"
...
}
}
Anyone has any ideas if this is doable using node-config or different library that works similar to node-config?
Thanks & regards Tin
The short answer is NO. node-config doesn't support this (As @Mark's response).
The simplest way to do this using node-config is to use JavaScript as config files ( https://github.com/lorenwest/node-config/wiki/Configuration-Files#javascript-module---js ). This way you still get most of the benefits of using node-config. Then you can simply include other files inside them ( https://github.com/lorenwest/node-config/wiki/Special-features-for-JavaScript-configuration-files#including-other-files )
Note that it would be a bit harder to use the multiple config files and overrides for the inner files.
A slightly more complex implementation can use the utility class in config which actually allows you to directly read a specific folder using the same patterns that node-config uses internally ( https://github.com/lorenwest/node-config/wiki/Using-Config-Utilities#loadfileconfigsdirectory ). In that case you would probably want to combine all the files to a single config by setting them on the config object before the first call to get ( https://github.com/lorenwest/node-config/wiki/Configuring-from-an-External-Source ).
I use nconf . It lets you read multiple configuration files into the same object. Here is an example:
var nconf = require('nconf');
//read the config files; first parameter is a required key
nconf.file('aws', {file: 'default-aws.json'});
nconf.file('db', {file: 'db-default.json'});
console.log(nconf.get('aws:kinesis'));
console.log(nconf.get('db:host'));
default-aws.json:
{
"aws": {
"kinesis": "my-stream"
}
}
db-default.json:
{
"db": {
"host": "my-host"
}
}
I'm a maintainer of node-config
. The next version will support a feature to declare multiple NODE_ENV
values, separated by a comma.
So if you were doing development in the cloud, you could declare a "development" environment followed by a "cloud" environment.
First the development config would be loaded, followed by the "cloud" config.
The related pull request is #486 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.