aboutsummaryrefslogtreecommitdiff
path: root/node_modules/rc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/rc/README.md')
-rw-r--r--node_modules/rc/README.md82
1 files changed, 80 insertions, 2 deletions
diff --git a/node_modules/rc/README.md b/node_modules/rc/README.md
index 65a5f0687..e6522e267 100644
--- a/node_modules/rc/README.md
+++ b/node_modules/rc/README.md
@@ -40,7 +40,7 @@ appCfg.config // same as appCfg.configs[appCfg.configs.length - 1]
Given your application name (`appname`), rc will look in all the obvious places for configuration.
- * command line arguments (parsed by minimist)
+ * command line arguments, parsed by minimist _(e.g. `--foo baz`, also nested: `--foo.bar=baz`)_
* environment variables prefixed with `${appname}_`
* or use "\_\_" to indicate nested properties <br/> _(e.g. `appname_foo__bar__baz` => `foo.bar.baz`)_
* if you passed an option `--config file` then from that file
@@ -59,7 +59,7 @@ so that sources **earlier** in this list override later ones.
## Configuration File Formats
-Configuration files (e.g. `.appnamerc`) may be in either [json](http://json.org/example) or [ini](http://en.wikipedia.org/wiki/INI_file) format. The example configurations below are equivalent:
+Configuration files (e.g. `.appnamerc`) may be in either [json](http://json.org/example) or [ini](http://en.wikipedia.org/wiki/INI_file) format. **No** file extension (`.json` or `.ini`) should be used. The example configurations below are equivalent:
#### Formatted as `ini`
@@ -114,6 +114,84 @@ Comments are stripped from JSON config via [strip-json-comments](https://github.
> Since ini, and env variables do not have a standard for types, your application needs be prepared for strings.
+To ensure that string representations of booleans and numbers are always converted into their proper types (especially useful if you intend to do strict `===` comparisons), consider using a module such as [parse-strings-in-object](https://github.com/anselanza/parse-strings-in-object) to wrap the config object returned from rc.
+
+
+## Simple example demonstrating precedence
+Assume you have an application like this (notice the hard-coded defaults passed to rc):
+```
+const conf = require('rc')('myapp', {
+ port: 12345,
+ mode: 'test'
+});
+
+console.log(JSON.stringify(conf, null, 2));
+```
+You also have a file `config.json`, with these contents:
+```
+{
+ "port": 9000,
+ "foo": "from config json",
+ "something": "else"
+}
+```
+And a file `.myapprc` in the same folder, with these contents:
+```
+{
+ "port": "3001",
+ "foo": "bar"
+}
+```
+Here is the expected output from various commands:
+
+`node .`
+```
+{
+ "port": "3001",
+ "mode": "test",
+ "foo": "bar",
+ "_": [],
+ "configs": [
+ "/Users/stephen/repos/conftest/.myapprc"
+ ],
+ "config": "/Users/stephen/repos/conftest/.myapprc"
+}
+```
+*Default `mode` from hard-coded object is retained, but port is overridden by `.myapprc` file (automatically found based on appname match), and `foo` is added.*
+
+
+`node . --foo baz`
+```
+{
+ "port": "3001",
+ "mode": "test",
+ "foo": "baz",
+ "_": [],
+ "configs": [
+ "/Users/stephen/repos/conftest/.myapprc"
+ ],
+ "config": "/Users/stephen/repos/conftest/.myapprc"
+}
+```
+*Same result as above but `foo` is overridden because command-line arguments take precedence over `.myapprc` file.*
+
+`node . --foo barbar --config config.json`
+```
+{
+ "port": 9000,
+ "mode": "test",
+ "foo": "barbar",
+ "something": "else",
+ "_": [],
+ "config": "config.json",
+ "configs": [
+ "/Users/stephen/repos/conftest/.myapprc",
+ "config.json"
+ ]
+}
+```
+*Now the `port` comes from the `config.json` file specified (overriding the value from `.myapprc`), and `foo` value is overriden by command-line despite also being specified in the `config.json` file.*
+
## Advanced Usage