1.0.5 • Published 2 years ago
use-config-json v1.0.5
use-config-json
Load config.json without hassle
Install
$ npm i --save use-config-json
Usage
// CommonJS
const {loadConfig} = require('use-config-json');
/**
JSON object, we will use this as a schema & fallback to default config value.
Format: {
[key: string]: "any"
}
const example = {
"host": "127.0.0.1",
"port": 3000
}
// This should be your default config file location to parse - if this value is undefined module will always try to load config.json
const configFile = 'config.json'
const config = loadConfig(example, 'config.json')
console.log(config);
**/
const defaultConfig = {
"host": "127.0.0.1",
"port": 3000
}
const config = loadConfig(defaultConfig);
console.log(config);
// ES6 Modules
import loadConfig from 'use-config-json';
const defaultConfig = {
"host": "127.0.0.1",
"port": 3000
}
const config = loadConfig(defaultConfig);
console.log(config);
// TypeScript
import * as loadConfig from 'use-config-json';
const defaultConfig = {
"host": "127.0.0.1",
"port": 3000
}
const config: object = loadConfig(defaultConfig);
console.log(config);
Note
Note that nested objects wouldn't be parsed from process.env
or either .env
file as well