Confi
Confi loads configuration data from yaml, json or from a package.json
with support for NODE_ENV
overrides.
Installation
npm install confi
or
yarn add confi
Usage
Note: confi()
is an async method.
Note: Default configuration directory is ./conf/
Configuration files that start with default
are loaded and merged together. This allows you to split up configuration logic into smaller files.
You can create a file that matches NODE_ENV
which will apply it's values on top of anything set in default. This allows you to create configuration for production and development environments.
User specific configuration can be created as well by placing config files in a users
directory inside of the config directory.
./conf/default.yaml
title: 'Example Site'
site:
name: '{{ title }} - DEV'
updateEvery: '{{ ms("1h") }}
appId: '{{ getEnv("APP_ID", '09830948029384') }}'
shot: false
./conf/users/han.json
{
"shot": true
}
./conf/production.yaml
site:
name: '{{ title }}'
updateEvery: '{{ getEnv("UPDATE_EVERY", ms("1h")) }}'
Basic
const confi = require('confi');
async function startApp() {
const config = await confi();
console.log(config.site.name);
console.log(config.appId);
console.log(config.updateEvery);
console.log(config.shot);
}
startApp();
User
const confi = require('confi');
async function startApp() {
const config = await confi({
user: 'han'
});
console.log(config.site.name);
console.log(config.appId);
console.log(config.updateEvery);
console.log(config.shot);
}
startApp();
Environment
const confi = require('confi');
async function startApp() {
const config = await confi({
env: 'production'
});
console.log(config.site.name);
console.log(config.appId);
console.log(config.updateEvery);
console.log(config.shot);
}
startApp();
For more examples, see the test directory.
Options
confi([options])
path
- Supply an alternate path to load config from. Default: process.env.CONFI_PATH
or ./conf
env
- Manually set the envitonment. Default: dev
userPath
- Path for user overrides. Default: ./conf/users
context
- Advanced option to pass additional information to varson
for parsing configs.helpers
- Additional helper methods to expose.user
- Which user shall the user config be loaded for.
Helpers
Confi comes with a set of helper methods. You can find documentation for them here.
![](https://firstandthird.com/_static/ui/images/safari-pinned-tab-62813db097.svg)
A First + Third Project