@slyncio/app-config v1.0.1
Simple App Config for your applications
Installation
Using npm in your app directory:
$ npm i --save @slyncio/app-config
Setup
- Create a root config directory
- While this defaults to directory named
config
in your app directory, it can be overrriden by settingAPP_CONFIG_ROOT
env variable relative to current working directory - Your default config files (
.json
or.js
) should be under<config root>/default
directory
Usage
Sample json in
<config root>/default/db.json
{ "host": "foo.bar.com", "port": 5432, "tables": ["users", "role", "tokens"], "user": { "name": "dbuser", "password": "frhhbwfefwef" } }
Config usage in your app
const Config = require('@slyncio/app-config')() const dbHost = Config.get('db.host') // foo.bar.com const rTable = Config.get('db.tables[1]') // role const username = Config.get('db.user.name') // dbuser
Environment specific config
- Environment specific configs can be used to override the default ones
- You can create any environment directories under the
config
folder - Current environment is determined by
NODE_ENV
orAPP_CONFIG_ENV
environment variables - The default environment is set to
development
Environment variable overrides
- Create a directory names
env
under<config root>
- Run
./node_modules/.bin/app-config
to auto generate config files with environment variables - You can chose a custom prefix by doing this
APP_CONFIG_VAR_PREFIX=<CUSTOM_PREFIX> ./node_modules/.bin/app-config
License
Copyright (c) 2018 Slync, Inc. https://slync.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.