n4v-config
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

net4VISIONS Config class

Provides handling of JSON application configuration with caching and reread of changed files.

Installation

npm i n4v-config

Features

  • Default config file is "app.json"
  • Tries to use a file "app_<NODE_ENV>.json" if NODE_ENV is set, falls back to default app.json
  • If specified a custom config file, like myconfig.json, it tries "myconfig_<NODE_ENV>.json"
  • Checks for valid properties with the help of a compare object with dummy values. Throws a ConfigError.
  • There is also Config.getInstance() without checking.
  • Caches the config and rereads file only if file modification time is newer.

Usage

TypeScript

import { Config, ConfigError, IConfig } from 'n4v-config';
 
interface IMyConfig extends IConfig {
  myProperty: string;
}
 
const compareObj: MyConfig = {
  myProperty: ''
};
 
const cfg = Config.getCheckedInstance<IMyConfig>(compareObj, './myconfig.json');
 
console.log('myProperty: %s', cfg.myProperty);
 

JavaScript

const config = require('n4v-config');
const Config = config.Config;
const ConfigError = config.ConfigError;
 
const compareObj = {
  myProperty: ''
};
 
const cfg = Config.getCheckedInstance(compareObj, './myconfig.json');
 
console.log('myProperty: %s', cfg.myProperty);
 

Package Sidebar

Install

npm i n4v-config

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

33.4 kB

Total Files

27

Last publish

Collaborators

  • arlecchino