Hapi Configue Plugin
Config plugin for Hapi.
CONFIGUE
RENAMED TOThis node.js module is being renamed to Configue, dropping the
hapi-
Prefix
Release
v0.7.1
is to warn of the migration!
Configue is a wrapper on nconf node hierarchical plugin tool. It defines a standard workflow to load a config from environment variables, command line arguments, files, that you can easily configure and extend.
About Configue
Configue builds up on nconf and its Hierarchical configuration system. It defines a list of configuration step that are executed in order. Every property defined on a steps will shadow the same key in the following steps.
Quoting nconf: "The order in which you attach these configuration sources determines their priority in the hierarchy"
Here are the standard steps Configue does define:
argv
: command line optionenv
: environment variablesfile
: config filesdefaults
: default objects
The plugin loads the various configurations in order using predefined steps. It starts by parsing argv then goes through the env and the files options and finishes by loading the default config objects if any. Hence why every option defined as an argument commandline will override defaults and environment variables.
Installation
Just add hapi-configue
has a dependency installing it with npm.
npm install --save hapi-configue
Usage
Basic usage without customization
server;
You can specify the who
configue in different manners.
Here are some:
node basic.js --who=Woman# configue through Env export who=Man ; node basic.jswho=Human node basic.js
The full example is available in the examples
folder.
Usage with customization of the configuration workflow
Specifying Files
The files key can contain a single object or an array of objects containing a file key containing the path to the config file. The object can also reference a nconf plugin tasked with the formatting using the key format.
const server = ;server;server;
Disabling Steps
The argv and env steps can be skipped using the disable
object in options
.
const server = ;server;server;
Step hooks
Every step has a post hook available.
Those can be defined using the postHooks
key and accept a
function that take nconf
as a parameter and a callback as a parameter.
The special hooks overrides
enables you to respectively apply a hook at the very beginning.
const server = ;server;server;
Custom Workflow
If needed you can have your full custom configuration workflow,
simply by providing an object with the single key customWorkflow
const configueOptions = { // my own config setting}; server;