Extends optimist
npm module with support for JSON/YAML config file and Docker's inspired environment variables handling.
How to use it
Refer to
examples/example.js
npm install --save optimist-config-file
const program = ; program // ... ; // handle --config option for passing YAML/JSON config filesprogram; // allow env variables to be passedprogram; // parse optionsconst options = program; console;
Example
YAML config file:
banner: Hello, ${USERNAME}! Greetings from ${HOSTNAME:-The Unknown Machine}.
Invocations with environment variables and options:
./example.js --config config.yamlHello, macbre! Greetings from The Unknown Machine. HOSTNAME=`hostname` ./example.js --config config.yamlHello, macbre! Greetings from debian. ./example.js --config config.yaml --banner='foo'Hello, macbre! Greetings from The Unknown Machine.
As you can see config file values have precedence over command line ones.