USE THIS MODULE TO LOAD ALL YOUR CONFIGURATIONS
This module is frozen.
//npm install config-chainvar cc =opts = argv //ALWAYS USE OPTIMIST FOR COMMAND LINE OPTIONS.env = optsenv || processenvYOUR_APP_ENV || 'dev' //SET YOUR ENV LIKE THIS.// EACH ARG TO CONFIGURATOR IS LOADED INTO CONFIGURATION CHAIN// EARLIER ITEMS OVERIDE LATER ITEMS// PUTS COMMAND LINE OPTS FIRST, AND DEFAULTS LAST!//strings are interpereted as filenames.//will be loaded synchronouslyvar conf =var host = conf// orvar host = confstorehost
FINALLY, EASY FLEXIBLE CONFIGURATIONS!
see also: proto-list
WHATS THAT YOU SAY?
YOU WANT A "CLASS" SO THAT YOU CAN DO CRAYCRAY JQUERY CRAPS?
EXTEND WITH YOUR OWN FUNCTIONALTY!?
var cc =// all the stuff you did beforevar config =// CONFIGS AS A SERVICE, aka "CaaS", aka EVERY DEVOPS DREAM OMG!// ASYNC FTW!// OBJECTS ARE OK TOO, they're SYNC but they still ORDER RIGHT// BECAUSE PROMISES ARE USED BUT NO, NOT *THOSE* PROMISES, JUST// ACTUAL PROMISES LIKE YOU MAKE TO YOUR MOM, KEPT OUT OF LOVE// DIE A THOUSAND DEATHS IF THIS EVER HAPPENS!!// THROW A PARTY IN YOUR FACE WHEN ITS ALL LOADED!!
MAKE A CHAIN AND ADD ALL THE ARGS.
If the arg is a STRING, then it shall be a JSON FILENAME.
RETURN THE CHAIN!
Join the args INTO A JSON FILENAME!
SEEK the RELATIVE PATH by climbing the TREE OF DIRECTORIES.
RETURN THE FOUND PATH!
Parse the content string, and guess the type from either the specified type or the filename.
RETURN THE RESULTING OBJECT!
Get all the keys on the provided env object (or process.env) which are prefixed by the specified prefix, and put the values on a new object.
RETURN THE RESULTING OBJECT!
The ConfigChain class for CRAY CRAY JQUERY STYLE METHOD CHAINING!
One of these is returned by the main exported function, as well.
It has all the methods from both, and except where noted, they are unchanged.
A list of all the places where it got stuff. The keys are the names passed to addFile or addUrl etc, and the value is an object with some info about the data source.
Filename is the name of the file. Name is an arbitrary string to be used later if you desire. Type is either 'ini' or 'json', and will try to guess intelligently if omitted.
Loaded files can be saved later.
Same as the filename thing, but with a url.
Can't be saved later.
Add all the keys from the env object that start with the prefix.
Parse the string and add it to the set. (Mainly used internally.)
Add the object to the set.
The root from which all the other config objects in the set descend prototypically.
Put your defaults here.
Set the key to the value on the named config object. If name is unset, then set it on the first config object in the set. (That is, the one with the highest priority, which was added first.)
Get the key from the named config object explicitly, or from the resolved configs if not specified.
Write the named config object back to its origin.
Currently only supported for env and file config types.
For files, encode the data according to the type.
When one or more files are saved, emits
save event when they're all
When the config chain has loaded all the specified files and urls and such, the 'load' event fires.