app-conf
Usage
The following files are looked up and merged (the latest take
precedence):
- vendor:
config.*
in the application directory; - global:
/etc/my-application/config.*
; - user:
~/.config/my-application/config.*
; - local:
/.my-application.*
down to ./.my-application.*
in the current
working directory;
Note: the local config is relative to the current working directory and
only makes sense for CLIs.
var loadConfig = require("app-conf").load;
loadConfig("my-application", {
appDir: __dirname,
defaults: {},
entries: ["vendor", "global", "user", "local"],
ignoreUnknownFormats: false,
}).then(function(config) {
console.log(config);
});
Relative paths, string values starting by ./
or ../
, are automatically
resolved from the config file directory.
Paths relative to the home directory, string values starting by ~/
, are also
automatically resolved.
JSON format is supported natively but you may install the following
packages to have additional features:
watch(opts, cb)
This method reload the configuration every time it might have changed.
const watchConfig = require("app-conf").watch;
const stopWatching = await watchConfig(
{
appDir: __dirname,
appName: "my-application",
},
(error, config) => {
if (error !== undefined) {
console.warn("loading config has failed");
stopWatching();
return;
}
console.log("config has been loaded", config);
}
);
Contributing
Contributions are very welcome, either on the documentation or on
the code.
You may:
- report any issue
you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet