Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/node-viper
config loader for NodeJS
https://github.com/zcong1993/node-viper
Last synced: about 23 hours ago
JSON representation
config loader for NodeJS
- Host: GitHub
- URL: https://github.com/zcong1993/node-viper
- Owner: zcong1993
- License: mit
- Created: 2019-01-24T11:34:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T22:08:59.000Z (about 3 years ago)
- Last Synced: 2023-02-28T14:37:11.729Z (over 1 year ago)
- Language: TypeScript
- Size: 394 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-viper
[![NPM version](https://img.shields.io/npm/v/@zcong/viper.svg?style=flat)](https://npmjs.com/package/@zcong/viper) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/viper.svg?style=flat)](https://npmjs.com/package/@zcong/viper) [![CircleCI](https://circleci.com/gh/zcong1993/node-viper/tree/master.svg?style=shield)](https://circleci.com/gh/zcong1993/node-viper/tree/master) [![codecov](https://codecov.io/gh/zcong1993/node-viper/branch/master/graph/badge.svg)](https://codecov.io/gh/zcong1993/node-viper)
> config loader for NodeJS
## Usage
```js
const { Viper } = require('@zcong/viper')const viper = new Viper({
configName: 'config',
configPaths: ['.'],
configTypes: ['json']
})console.log(viper.loadFiles())
console.log(viper.loadEnv())
```### config
```ts
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/test` will 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