Intro | Quick start | Quick start (ES6) | API | Contributors | TODO
Intro
Why not
config
?
Answer. TL;DR: config
separates data to different files based on NODE_ENV
, not resources.
$ npm install no-config
Quick start
// config.jsmoduleexports = redis: { return } default: db: 0 port: 6379 development: host: '127.0.0.1' production: db: 1 host: '192.168.0.10'
// index.js config:
$ NODE_ENV=development node index.js
ENV development
Redis: 127.0.0.1:6379
Quick start (ES6)
Since no-config returns a promise it is much better to use ES6 generators, arrow functions and co.
If you are not familiar with co, check this step-by-step tutorial
// config.jsmoduleexports = redis: default: db: 0 port: 6379 development: host: '127.0.0.1' production: db: 1 host: '192.168.0.10'
// index.js'use strict'const co =
API
Loader
parameters
Loads resources from parameters.config
based on NODE_ENV
environment variable. Returns a Promise which resolves ones all resources are initialized.
Parameters
Name | Required? | Type | Default | Description |
---|---|---|---|---|
config |
Required | Object | Configuration object | |
init |
Optional | List of strings | All Resources | Resources to initialize |
verbose |
Optional | Boolean | false |
Print resource input prior to call its init() function |
mask_secrets |
Optional | Boolean | true |
if verbose === true will hide input value if its key contains substrings: secret , token , key , pass or pwd |
Configuration object
Every high-level key in configuration object is a resource name.
Name | Required? | Type | Default | Description. Handling |
---|---|---|---|---|
<RESOURCE> |
Optional | Object | Resource configuration | |
<RESOURCE>.defaut |
Optional | Object | {} |
Default values |
<RESOURCE>.<ENV> |
Optional | Object | {} |
ENV specific values. If a key duplicates default key, env-specific value is used |
<RESOURCE>.init |
Optional | Function, Generator function | Called to initalize resource, <RESOURCE>.init(result) . If returns Promise or Generator, it got resolved with co. Result is saved to result.instance . |
Contributors
Fedor Korshunov - view contributions
Anurag Sharma - view contributions