This Node.js module manages configuration settings by reading from and writing to a config-sets.json
file.
It handles command-line arguments and watches for changes to the configuration file.
It allows you to create applications that can be configured in real time.
This manual is also available in HTML5.
Please note, this version is not backward compatible with version 2.x
Please note that JSON string is not 100% compatible.
It has been extended to allow for incremental updates of JSON files.
Added the ability to include metadata and comments.
Parsing of JSON files is enabled.
To install the module, use npm:
npm install config-sets
To use the module, require it in your script and call the configSets
function:
const configSets = require('config-sets');
const config = configSets({
'-metadata-key1': ' key1 comment ',
key1: 'value1',
'-metadata-key2': ' key2 comment ',
key2: 'value2'
});
const moduleConfig = configSets('moduleName', { key1: 'value1', key2: 'value2' });
console.log(config);
config.on('key1', function (ev) { console.log(ev); return true; });
file: config-sets.json
{
"isProduction": true,
"production": {
/* key1 comment */
"key1": "value1",
/* key2 comment */
"key2": "value2",
"moduleName": {
"key1": "value1",
"key2": "value2"
}
},
"development": {}
}
You can pass configuration settings via command-line arguments:
node index.js --key1=value1 --key2=value2
node index.js --help
The module watches the config-sets.json
file for changes and updates the configuration settings accordingly.
This uses the 'data-context' module. Read more about how to use it.
config.on('key1', function (ev) { console.log(ev); return true; });
You can test config-sets
on your system using this command:
node ./node_modules/config-sets/index.test
or in the config-sets
project directory:
npm test
configModuleName
(optional): The name of the module to set or update configuration settings for.defaultConfigSettings
: The default configuration settings.
Returns the current configuration settings.
configSets.isProduction
: Indicates if the environment is production.configSets.production
: Contains production-specific configuration settings.configSets.development
: Contains development-specific configuration settings.configSets.isSaveChanges
(default: true): Determines if changes to the configuration should be saved automatically.
target
: The target object to merge properties into.source
: The source object containing properties to merge.overwriteChanges
(optional): A boolean indicating whether to overwrite existing properties in the target object.
Merges source objects into a target object.
Parses command-line arguments into an object.
Returns an object containing the parsed command-line arguments.
Prints the help message.
This project is licensed under the MIT License.
Copyright © 2025 Manuel Lõhmus
Donations are welcome and will go towards further development of this project.