dominictarr/rc is a JavaScript project with 1.0k stars. The non-configurable configuration loader for lazy people.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
The non-configurable configuration loader for lazy people.
Usage
The only option is to pass rc the name of your app, and your default configuration.
var conf = require('rc')(appname, {
//defaults go here.
port: 2468,
//defaults which are objects will be merged, not replaced
views: {
engine: 'jade'
}
});
rc will return your configuration options merged with the defaults you specify.
If you pass in a predefined defaults object, it will be mutated:
var conf = {};
require('rc')(appname, conf);
If rc finds any config files for your app, the returned config object will have
a configs array containing their paths:
var appCfg = require('rc')(appname, conf);
appCfg.configs[0] // /etc/appnamerc
appCfg.configs[1] // /home/dominictarr/.config/appname
appCfg.config // same as appCfg.configs[appCfg.configs.length - 1]
Standards
Given your application name (appname), rc will look in all the obvious places for configuration.
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 (e.g. appname_foo__bar__baz => foo.bar.baz)
if you passed an option --config file then from that file
a local .${appname}rc or the first found looking in ./ ../ ../../ ../../../ etc.
$HOME/.${appname}rc
$HOME/.${appname}/config
$HOME/.config/${appname}
$HOME/.config/${appname}/config
/etc/${appname}rc
/etc/${appname}/config
the defaults object you passed in.
All configuration sources that were found will be flattened into one object,
so that sources earlier in this list override later ones.
Configuration File Formats
Configuration files (e.g. .appnamerc) may be in either json or ini format. No file extension (.json or .ini) should be used. The example configurations below are equivalent:
Formatted as ini
; You can include comments in `ini` format if you want.
dependsOn=0.10.0
; `rc` has built-in support for ini sections, see?
[commands]
www = ./commands/www
console = ./commands/repl
; You can even do nested sections
[generators.options]
engine = ejs
[generators.modules]
new = generate-new
engine = generate-backend
Formatted as json
{
// You can even comment your JSON, if you want
"dependsOn": "0.10.0",
"commands": {
"www": "./commands/www",
"console": "./commands/repl"
},
"generators": {
"options": {
"engine": "ejs"
},
"modules": {
"new": "generate-new",
"backend": "generate-backend"
}
}
}
Comments are stripped from JSON config via strip-json-comments.
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 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):
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.
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
Pass in your own argv
You may pass in your own argv as the third argument to rc. This is in case you want to use your own command-line opts parser.
If you have a special need to use a non-standard parser,
you can do so by passing in the parser as the 4th argument.
(leave the 3rd as null to get the default args parser)
require('rc')(appname, defaults, null, parser);
This may also be used to force a more strict format,
such as strict, valid JSON only.
Note on Performance
rc is running fs.statSync-- so make sure you don't use it in a hot code path (e.g. a request handler)
License
Multi-licensed under the two-clause BSD License, MIT License, or Apache License, version 2.0
The most recent commit recorded on dominictarr/rc was 4.4 years ago, based on the GitHub push timestamp. The repository has 99 forks — one of the better signals of community interest.
How many stars does dominictarr/rc have?
dominictarr/rc has 1.0k GitHub stars — refresh the page for the live number, or check github.com/dominictarr/rc. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is dominictarr/rc open source?
TopGit's metadata for dominictarr/rc does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is dominictarr/rc?
dominictarr/rc (dominictarr/rc) is a JavaScript project on GitHub. From the project's own README: The non-configurable configuration loader for lazy people.
Where do I read more about dominictarr/rc?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/dominictarr/rc is the definitive source.
Read full README in the tab above.
Is rc worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of rc.