configo

0.1.2 • Public • Published
┌─┐┌─┐┌┐┌┌─┐┬┌─┐┌─┐
│  │ ││││├┤ ││ ┬│ │
└─┘└─┘┘└┘└  ┴└─┘└─┘

configo

Hierarchical configuration with files and environment variables for node and the browser.

NPM Version Code Climate

Install

npm i --save configo

Usage

1. Create a config folder at the root of your project. Within it, create a default folder.

mkdir config
mkdir 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.js
module.exports = {
  WHO_IS_BATMAN: 'Bruce Wayne'
};
// ./config/default/public.js
module.exports = {
  NODE_ENV: process.env.NODE_ENV
};

3. Require configo on the server and in browsers (using browserify) and easily access your configuration variables.

// On the server
var conf = require('configo');
 
console.log(conf.get('WHO_IS_BATMAN')); // Bruce Wayne
console.log(conf.get('NODE_ENV'));      // production
// In browsers
var conf = require('configo');
 
console.log(conf.get('WHO_IS_BATMAN')); // undefined
console.log(conf.get('NODE_ENV'));      // 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 = require('configo');
 
var AWS_SECRET_KEY = conf.get('AWS_SECRET_KEY'); // 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 = require('configo');
 
conf.set('FOO', 'bar');
console.log(conf.get('FOO')); // bar

Package Sidebar

Install

npm i configo

Weekly Downloads

3

Version

0.1.2

License

none

Last publish

Collaborators

  • naoufal