npm.io
2.1.0 • Published 2 weeks ago

@openally/config

Licence
MIT
Version
2.1.0
Deps
3
Size
55 kB
Vulns
0
Weekly
0

Config

Reactive configuration loader with safe hot reload configuration upon JSON Schema

Requirements

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/config

Features

  • 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 .nodesecurerc for 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();

config.json should exists otherwise it will throw an Error. Look at createOnNoEntry option for more information !

API

License

MIT

Keywords