title: node.js global configuration
body: <p>I'm currently working on a small console project that depends a lot on the arguments that are passed initially and I'm looking for a good way to handle a configuration object in nodejs.</p>
  
  <p>I have the project currently fully working with the following example but I think I'm relaying on the caching of modules when using 'require'.</p>
  
  <p>lets assume a module options.js</p>
  
  <pre><code>'use strict';
  
  var options = {
      configName: '.jstail',
      colorActive: (process.platform === 'win32') ? false : true, // deactivate color by default on windows platform
      quiet: false,
      debug: false,
      config: null,
      logFile: null,
      setting: null
  };
  
  module.exports = options;
  </code></pre>
  
  <p>And my initial module init.js</p>
  
  <pre><code>#!/usr/bin/env node
  'use strict';
  
  var options = require('options'); // require above options module
  
  // modify the options object based on args
  </code></pre>
  
  <p>I then have a logger that depends on this options</p>
  
  <p>For example if quiet is set to true no logging should happen</p>
  
  <p>logger.js</p>
  
  <pre><code>'use strict';
  
  var options = require('options');
  
  /**
   * prints to console if not explicitly suppresed
   * @param {String} text
   */
  function log(text) {
     if (!options.quiet) {
         console.log('[LOG]: ' + text);
     }
  }
  </code></pre>
  
  <p>My big problem is (I think) that I'm relaying on the caching of nodejs modules when I require the options module in the logger</p>
  
  <p>So my two questions are:</p>
  
  <p>Am I right that this only works because of the caching of the modules that nodejs does for me?
  Is there any better way to handle a dynamic global configuration?</p>
  
  <p>I know there are several questions and tutorials around with a config file but thats not what I'm looking for.</p>