Qconf
Painless configuration with defaults file, environment variables, arguments, function parameters.
Install / Use
/learn @ericelliott/QconfREADME
qconf
Painless configuration for Node apps with defaults file, environment variables, arguments, function parameters.
defaults file < process.env < command line arguments < function call override
Status: No Longer Maintained
This repo is no longer actively maintained.
Getting started
Create your config object:
var qconf = require('qconf.js'),
config = qconf(); // 99% of the time, this is all you need!
Extra credit
Create a JSON file: ./config/config.json
{
"default_setting": true,
"envOverride": false,
"arg_override": false,
"param_override": false
}
Maybe source some environment variables:
export env_override=true
Try a command-line option:
node myfile.js --arg-option true
Result
Painless configuration for your apps!
Motivation
Got sick of the complexity of nconf. Don't try to be everything to everybody. Just get a simple job done with simple code.
API
qconf()
This is the function that gets imported when you require qconf.
Creates a configuration object for your app by reading configuration settings from a defaults file, environment variables, command line arguments, and finally a function parameters hash, in reverse priority.
- @param {Object} [overrides] A map of config keys and values.
- @param {Array} || {String} [filesURI] An array of config files in order of precedence (least to most) or path to the defaults file. Can be the only parameter.
- @return {Object} config A configuration object.
- @return {Function} config.get The get method.
- @return {Function} config.set The set method.
More examples using overrides. File overrides support JSON and YAML files:
var qconf = require('qconf'),
// You can pass in an array of configuration files.
// Last in wins:
config = qconf(['file://config/defaults.json', 'file://config/overrides.yml']);
var qconf = require('qconf'),
// You can pass in argument overrides and file overrides.
// Argument overrides win.
config = qconf({override: 'This setting trumps all.'},
['file://config/defaults.json', 'file://config/overrides.yml']);
The config object
The config object is the object returned when you call qconf(). This is the getter and setter for all your app's environment variables.
config.get()
Return the value of the attribute requested.
- @param {String} attr The name of the attribute to return.
- @return {Any} The value of the requested attribute.
config.set()
Set the value of an attribute.
- @param {String} attr The name of the attribute to set.
- @param {Any} value The value to set the attribute to.
- @return {Object} The config object (for chaining).
Events
The config object is an event emitter.
undefined
config.get() will emit the event 'undefined' if the value of the variable in question is undefined. It will also emit a convenient, searchable message that you can log and easily find in your logs:
'WARNING: Undefined environment variable: ' + `attr`
attr refers to the name of the variable you tried to get.
For example:
var qconf = require('qconf'),
config = qconf(),
util = require('util');
config.on('undefined', function (msg, attr) {
util.log(msg);
// or build a custom message:
util.log('WAT? Can\'t find ' + attr);
});
config.get('some_var');
// Logs:
// "WARNING: Undefined environment variable: some_var"
// "WAT? Can't find some_var"
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
