cat-config
v1.2.2
Published
Manage loading configulations
Readme
Install
yarn add cat-configExample
// conf.json file
{
"confA": "conf.json",
"confB": "conf.json"
}# conf.yaml file
confB: "conf.yaml"
confC: "conf.yaml"import CatConfig from 'cat-config';
const CONF = CatConfig({
confA: 'v_1',
confB: 'v_2',
confC: 'v_3'
})
.env()
.json()
.yaml()
.exec();
console.log(CONF);
/*
{
foo: 'bar',
confA: 'conf.json',
confB: 'conf.yaml',
confC: 'conf.yaml'
}
*/
set config from docker-compose.yml
# docker-compose.yml
version: '3.9'
services:
node:
image: nodejs
environment:
CONF: |
keyA: value_A
keyB: value_Bimport CatConfig from 'cat-config';
const CONF = CatConfig({
keyA: ''
keyB: ''
})
.loadEnv()
.exec();NODE_ENV
load config file with NODE_ENV environment
if NODE_ENV not set default is dev
const CONF = CatConfig({})
.yaml()
.js()
.json()If NODE_ENV is not set cat-config will load file
- conf.yaml
- conf.dev.yaml
- conf.js
- conf.dev.js
If NODE_ENV is set to test cat-config will load file
- conf.yaml
- conf.test.yaml
- conf.js
- conf.test.js
you can set conf.dev.* in .gitignore file
Merge
CAT_CONFIG__SOMETING will convert to
{
catConfig: {
someting: ''
}
}Options
mainPath
directory store config file
filename
prefix of config file
default is "conf"
freeze
use Object.freeze to freeze config
default is true
see Object.freeze()
Debug
debug with debug library
DEBUG=cat-config