1.1.0 • Published 5 years ago
@randlabs/js-config-reader v1.1.0
js-config-reader
Config Reader is a module to ease configuration settings load and validation with the help of JSON schemas.
Installation
npm install --save @randlabs/js-config-readerUsage
const ConfigReader = require("@randlabs/js-config-reader");
const settings = await ConfigReader.initialize(options);Example
const ConfigReader = require("@randlabs/js-config-reader");
const settings = await ConfigReader.initialize({
source: path.join(__dirname, "./settings.json"),
schema: path.join(__dirname, "./settings.schema.json")
});The options parameter is an object with the following fields:
source- Source location of the configuration settings. Can be a filename or url depending on the used loader. Optional.envVar- Environment variable name used to find the source. Optional. I.e.: Defineexport MY_SETTINGS=/home/myuser/settings.jsonand setMY_SETTINGSas theenvVar.cmdLineParam- Command-line parameter to use to find the source. Optional. I.e.: Ifsettingsis specified, then the code will look for the--settingscommand-line parameter.loader- Loader function used to load the configuration settings. Optional.schema- Schema location or JSON Schema object to validate configuration settings. Optional.schemaOpts- Additional options to pass to the JSON Schema validator. Optional.extendedValidator- Specifies an additional settings validator. Optional.usingClusters- Prepares usage for a cluster environment. Optional.
License
Apache 2.0