1.0.1 • Published 9 years ago

mr-config v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

Merges configurations from multiple files, as specified in the MR_CONFIGS_FILES environment variable. Allowing for easy loading of environmental configurations.

// apps.js
var config = require('mr-config');

// service.js
// Uses a cached copy of the configuration
var config = require('mr-config');
# config files are merged together. The right-most files
# will override existing duplicate properties.
MR_CONFIGS_FILES="/home/user/app-config.json, /home/user/db-config.json" node app.js

Installation

npm install mr-config

API

config.$configs | Array

The values retrieved from MR_CONFIGS_FILES

var confFiles = config.$configs
// [ 'app-config.json', 'db-config.json' ]

config.$timestamp | Number

The milliseconds since the epoch

var lastLoadTime = config.$timestamp
// 1443498715071

config.reload( parser )

Forces of reload of all config files into memory.

config.reload();
// Reloads config in place

If a custom parser is needed, reload() can be invoked with a function.

config.reload(function(filePath) {
  /*
   * Do Stuff
   */
  return object;
});

config.watch()

Creates a file system watcher for each configuration file

config.watch()
// Will reload config in memory if any of the files change

config.unwatch()

Closes and config file watchers

config.unwatch()
// Undoes the watch

Change Log

1.0.0
  • First release