┌─┐┌─┐┌┐┌┌─┐┬┌─┐┌─┐
│ │ ││││├┤ ││ ┬│ │
└─┘└─┘┘└┘└ ┴└─┘└─┘
configo
Hierarchical configuration with files and environment variables for node and the browser.
Install
npm i --save configo
Usage
1. Create a config
folder at the root of your project. Within it, create a default
folder.
mkdir configmkdir config/default
2. Within the default
folder, create a private.js
file that exports an Object
containing your private configuration variables. Once that's done, create a public.js
file that does the same but for your publicly accessible configuration variables.
// ./config/default/private.jsmoduleexports = WHO_IS_BATMAN: 'Bruce Wayne';
// ./config/default/public.jsmoduleexports = NODE_ENV: processenvNODE_ENV;
3. Require configo
on the server and in browsers (using browserify) and easily access your configuration variables.
// On the servervar conf = ; console; // Bruce Wayneconsole; // production
// In browsersvar conf = ; console; // undefinedconsole; // production
NOTE: Your private configuration variables are not included in the outputted browserify file.
Functions
get(key)
Retrieves a key from your config.
Arguments
key
- The variable you want to retrieve from your configuration.
Examples
var conf = ; var AWS_SECRET_KEY = conf; // SUPERSECRETAWSSECRETKEY
set(key, value)
Overwrites a variable in your configuration or sets a new one if the variable doesn't exist.
Arguments
key
- The name of the variable you want to overwrite or sets it on your configo instance.value
- The value you want to store.
Examples
var conf = ; conf;console; // bar