A simple, zero-dependency library helps you make a configuration for your library or module.
It helps you define a set of default parameters(in default.js
), and extend them(in local.js
or others files) recursively.
It is highly recommended to use lorenwest/node-config when you are willing to build an application rather than a library. It is a pretty awesome library and provides many useful features.
- Installation
- Quick Start
- Config Object
- Reserved Words
- Environment Variables
- API
- Versioning
- Copyright and License
npm install --save config-sp
-
mkdir a folder.
mkdir config
-
edit the default configuration via
vim config/default.js
.{ a: { b: { c: 'hello', c2: 'world', c3: 1, }, d: [1, 2, 3], }, e: false, f: null, g: 1, }
-
edit the local configuration via
vim config/local.js
.{ a: { b: { c: 'bye', c3: 0, }, d: [], }, e: true, g: undefined, h: null, }
-
edit the index file to indicate the default and local files via
vim config/index.js
.var Config = require('config-sp'); // the default.js and local.js are relative path to __dirname var config = Config.load(__dirname, ['default.js', 'local.js'], { ignores: 'local.js', // local.js is allowed to be missing }); // the config will be: // { // a: { // b: { // c: 'bye', // c2: 'world', // c3: 0, // }, // d: [], // }, // e: true, // f: null, // g: 1, // h: null, // } // to get a child config var c = config.get('a.b.c'); // or c = config.a.b.c; var a = config.get('a'); // the child config returned by `get` method, will also have `get` method c = a.get('b.c'); var b = config.a.b; // c = b.get('c'); // will throw an error, because `b` has no `get` method // var d = config.get('d'); // it will throw an error, because `d` is missing
The config object returned by load
and create
function will have get
method, which is used to get a child config.
get
method will throw an exception for undefined value to help catch typos and missing values.
the following configuration names cannot be used as config key:
- get
supported values:
- 'warn':
console.warn
the error message - 'error':
console.error
the error message - 'ignore': neither print anything nor throw an error
If CONFIG_SP_LOAD_FILE_MISSING
is not set, it will throw an error when the file is missing.
see http://adoyle.me/config-sp/
The versioning follows the rules of SemVer 2.0.0.
BUT, anything may have BREAKING CHANGES at ANY TIME when major version is zero (0.y.z), which is for initial development and the public API should not be considered stable.
For more information on SemVer, please visit http://semver.org/.
Copyright (c) 2015-2016 ADoyle. The project is licensed under the Apache License Version 2.0.
See the LICENSE file for the specific language governing permissions and limitations under the License.
See the NOTICE file distributed with this work for additional information regarding copyright ownership.