Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kolbma/node-n4v-config
Caching JSON application configuration
https://github.com/kolbma/node-n4v-config
Last synced: 21 days ago
JSON representation
Caching JSON application configuration
- Host: GitHub
- URL: https://github.com/kolbma/node-n4v-config
- Owner: kolbma
- Created: 2018-06-29T15:36:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T06:02:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-15T04:15:36.148Z (about 1 month ago)
- Language: TypeScript
- Size: 488 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 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_.json" if NODE_ENV is set, falls back to default app.json
- If specified a custom config file, like myconfig.json, it tries "myconfig_.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
``` TypeScript
import { Config, ConfigError, IConfig } from 'n4v-config';interface IMyConfig extends IConfig {
myProperty: string;
}const compareObj: MyConfig = {
myProperty: ''
};const cfg = Config.getCheckedInstance(compareObj, './myconfig.json');
console.log('myProperty: %s', cfg.myProperty);
```
### JavaScript
``` 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);
```