Skip to content

Latest commit

 

History

History
75 lines (57 loc) · 1.61 KB

README.md

File metadata and controls

75 lines (57 loc) · 1.61 KB

appfig

Combines nconf, recurpolate, and declarative JSON "extends" syntax to create an extremely useful configuration loader.

Build Status Coverage Status

Usage

All the value packed into appfig is demonstrated in ./example, which is summarized for your reading below. appfig is compatible with Node 8+. Enjoy.

config/default.json

{
  "port": 3000,
  "logLevel": "debug",
  "services": {
    "users": "http://${host}/users"
  }
}

config/development.json

{
  "extends": "default",
  "host": "dev.example.com"
}

config/production.json

{
  "extends": "default",
  "port": 3001,
  "logLevel": "info",
  "host": "www.example.com"
}

index.js

process.env.APP_ENV = process.env.APP_ENV || 'development';

const { APP_ENV } =  process.env;

const config = require('appfig')(__dirname + `/config/${APP_ENV}.json`);

console.log(config.get('port'));
console.log(config.get('logLevel'));
console.log(config.get('services:users'));

Starting your application with development configuration

$ node index.js

3000
trace
http://dev.example.com/users

Starting your application with production configuration

$ APP_ENV=production node index.js

3001
info
http://www.example.com/users

Use it

appfig is released under the MIT License.