@hkva/ezconfig
v1.0.2
Published
EZ Config Files
Downloads
2
Readme
node-ezconfig
EZ Config Files with Node.JS :ok_hand:
Example:
const EZConfig = require('@hkva/ezconfig');
const DEFAULT_CONFIG = {
_version: 1,
token: 'Some information here',
something: 12345,
admins: [
"me",
"you",
"your dog"
]
}
const config = new EZConfig('./config.json');
// Try to load the config from disk
if (!config.load()) {
// Config could not be loaded
console.error(`Config ${config.path} does not exist or could not be loaded`);
// Reset to default
config.reset(DEFAULT_CONFIG);
console.log('Config reset');
process.exit(1);
}
// Check config version
if (config.get('_version') < DEFAULT_CONFIG._version) {
console.info('Warning: Config is out of date');
}
console.log(`token: ${config.get('token')}`);
console.log(`Admins: ${config.get('admins').join(' ')}`);