@zcong/viper v0.1.5
node-viper
config loader for NodeJS
Usage
const { Viper } = require('@zcong/viper')
const viper = new Viper({
configName: 'config',
configPaths: ['.'],
configTypes: ['json']
})
console.log(viper.loadFiles())
console.log(viper.loadEnv())config
interface RootConfig {
configName?: string
configPaths?: string[]
configTypes?: supportTypes[]
envPrefix?: string
}RootConfig.configName
config file name without extension, eg: config, .env
RootConfig.configPaths
config file load paths, eg:
['.']if start with
$will be replaced by env, eg:$HOME/testwill be~/test
RootConfig.configTypes
config file extensions, allowed is array of type supportTypes = 'json' | 'yaml' | 'toml' | 'dotenv', default is ['json', 'yaml', 'toml', 'dotenv']
RootConfig.envPrefix
if set, only load key of env whitch has this prefix. eg: set RootConfig.envPrefix = 'VIPER', only load VIPER_TEST, VIPER_FILE, TEST will be ignored.
VIPER_ or VIPER will be treated as VIPER_
Viper
Viper.loadFiles()
search config files by the order of configPaths and configTypes , will load the first finded and valid config file as return.
Viper.loadEnv()
load config from env.
you can call both of the two method, but the first will be merged by the second.
License
MIT © zcong1993