@openally/config
v1.2.0
Published
Reactive configuration loader
Readme
Requirements
- Node.js v20 or higher
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @openally/config
# or
$ yarn add @openally/configFeatures
- Hot-reloading of configuration
- Reactive with observable key(s)
- Safe with JSON Schema validation
- Support TOML as input (enable the parser when the file extension end with .toml)
- Read configuration with no extension that start with a dot (like
.nodesecurercfor example).
Usage example
Create a simple json file for your project
{
"loglevel": 5,
"logsize": 4048,
"login": "administrator"
}Now, create a new Configuration instance and read it
import { AsynchronousConfig } from "@openally/config";
const config = new AsynchronousConfig("./path/to/config.json");
await config.read();
console.log(cfg.get("loglevel")); // stdout: 5
// Observe (with an Observable Like) the update made to login property
config.observableOf("login").subscribe(console.log);
config.set("login", "admin");
// Payload getter will return a deepClone with all configuration properties
console.log(config.payload);
config.close();[!IMPORTANT]
config.jsonshould exists otherwise it will throw an Error. Look atcreateOnNoEntryoption for more information !
API
License
MIT
