diff --git a/README.md b/README.md index 7157bd0..620b621 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# nconf +# nconf-lite -[![Version npm](https://img.shields.io/npm/v/nconf.svg?style=flat-square)](https://www.npmjs.com/package/nconf)[![npm Downloads](https://img.shields.io/npm/dm/nconf.svg?style=flat-square)](https://www.npmjs.com/package/nconf)[![Build Status](https://img.shields.io/travis/indexzero/nconf/master.svg?style=flat-square)](https://travis-ci.org/indexzero/nconf)[![Coverage](https://img.shields.io/coveralls/indexzero/nconf.svg?style=flat-square)](https://coveralls.io/github/indexzero/nconf)[![Dependencies](https://img.shields.io/david/indexzero/nconf.svg?style=flat-square)](https://david-dm.org/indexzero/nconf) +Hierarchical node.js configuration with files, environment variables, and atomic object merging. -Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging. +This is a fork of nconf without the bloated yargs dependancy. ## Example Using nconf is easy; it is designed to be a simple key-value store with support for both local and remote storage. Keys are namespaced and delimited by `:`. Let's dive right into sample usage: @@ -12,12 +12,10 @@ Using nconf is easy; it is designed to be a simple key-value store with support // // Setup nconf to use (in-order): - // 1. Command-line arguments // 2. Environment variables // 3. A file located at 'path/to/config.json' // - nconf.argv() - .env() + nconf.env() .file({ file: 'path/to/config.json' }); // @@ -47,13 +45,12 @@ Using nconf is easy; it is designed to be a simple key-value store with support If you run the above script: ``` bash - $ NODE_ENV=production sample.js --foo bar + $ NODE_ENV=production sample.js ``` The output will be: ``` - foo: bar NODE_ENV: production database: { host: '127.0.0.1', port: 5984 } ``` @@ -62,7 +59,6 @@ The output will be: Configuration management can get complicated very quickly for even trivial applications running in production. `nconf` addresses this problem by enabling you to setup a hierarchy for different sources of configuration with no defaults. **The order in which you attach these configuration sources determines their priority in the hierarchy.** Let's take a look at the options available to you - 1. **nconf.argv(options)** Loads `process.argv` using yargs. If `options` is supplied it is passed along to yargs. 2. **nconf.env(options)** Loads `process.env` into the hierarchy. 3. **nconf.file(options)** Loads the configuration data at options.file into the hierarchy. 4. **nconf.defaults(options)** Loads the data in options.store into the hierarchy. @@ -82,9 +78,8 @@ A sane default for this could be: // // 2. `process.env` - // 3. `process.argv` // - nconf.env().argv(); + nconf.env(); // // 4. Values in `config.json` @@ -183,7 +178,6 @@ You can also chain `.required()` calls when needed. for example when a configura ```js config - .argv() .env() .required([ 'STAGE']) //here you should have STAGE otherwise throw an error .file( 'stage', path.resolve( 'configs', 'stages', config.get( 'STAGE' ) + '.json' ) ) @@ -207,73 +201,6 @@ A simple in-memory storage engine that stores a nested JSON representation of th nconf.use('memory'); ``` -### Argv -Responsible for loading the values parsed from `process.argv` by `yargs` into the configuration hierarchy. See the [yargs option docs](https://github.com/bcoe/yargs#optionskey-opt) for more on the option format. - -#### Options - -##### `parseValues: {true|false}` (default: `false`) -Attempt to parse well-known values (e.g. 'false', 'true', 'null', 'undefined', '3', '5.1' and JSON values) -into their proper types. If a value cannot be parsed, it will remain a string. - -##### `transform: function(obj)` -Pass each key/value pair to the specified function for transformation. - -The input `obj` contains two properties passed in the following format: -``` -{ - key: '', - value: '' -} -``` - -The transformation function may alter both the key and the value. - -The function may return either an object in the same format as the input or a value that evaluates to false. -If the return value is falsey, the entry will be dropped from the store, otherwise it will replace the original key/value. - -*Note: If the return value doesn't adhere to the above rules, an exception will be thrown.* - -#### Examples - -``` js - // - // Can optionally also be an object literal to pass to `yargs`. - // - nconf.argv({ - "x": { - alias: 'example', - describe: 'Example description for usage generation', - demand: true, - default: 'some-value', - parseValues: true, - transform: function(obj) { - if (obj.key === 'foo') { - obj.value = 'baz'; - } - return obj; - } - } - }); -``` - -It's also possible to pass a configured yargs instance - -``` js - nconf.argv(require('yargs') - .version('1.2.3') - .usage('My usage definition') - .strict() - .options({ - "x": { - alias: 'example', - describe: 'Example description for usage generation', - demand: true, - default: 'some-value' - } - })); -``` - ### Env Responsible for loading the values parsed from `process.env` into the configuration hierarchy. By default, the env variables values are loaded into the configuration as strings. @@ -289,6 +216,9 @@ If this option is enabled, all calls to `nconf.get()` must pass in a lowercase s Attempt to parse well-known values (e.g. 'false', 'true', 'null', 'undefined', '3', '5.1' and JSON values) into their proper types. If a value cannot be parsed, it will remain a string. +#### `readOnly: {true|false}` (defaultL `true`) +Allow values in the env store to be updated in the future. The default is to not allow items in the env store to be updated. + ##### `transform: function(obj)` Pass each key/value pair to the specified function for transformation. @@ -307,9 +237,6 @@ If the return value is falsey, the entry will be dropped from the store, otherwi *Note: If the return value doesn't adhere to the above rules, an exception will be thrown.* -#### `readOnly: {true|false}` (defaultL `true`) -Allow values in the env store to be updated in the future. The default is to not allow items in the env store to be updated. - #### Examples ``` js @@ -328,7 +255,7 @@ Allow values in the env store to be updated in the future. The default is to not // // Can also lowerCase keys. // Especially handy when dealing with environment variables which are usually - // uppercased while argv are lowercased. + // uppercased. // // Given an environment variable PORT=3001 diff --git a/package.json b/package.json index 7aa3340..a67ba03 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "nconf", + "name": "nconf-lite", "description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.", "version": "0.9.1", "author": "Charlie Robbins ", @@ -11,7 +11,7 @@ ], "repository": { "type": "git", - "url": "http://github.com/flatiron/nconf.git" + "url": "http://github.com/nfp-projects/nconf-lite.git" }, "keywords": [ "configuration",