title: node.js configure submodules
body: <p>[EDIT]</p>
  <p>Thanks to Stafano that formalized my question in a better way:
  You have a module</p>
  <blockquote>
  <p>-) There are several files in this module</p>
  <p>-) All these files depend on a configuration whose path is unknown to the module itself</p>
  <p>-) This module does not do much on its own, and is meant to be used by other applications</p>
  <p>-) These applications should inject a configuration path into the module before it can be used</p>
  </blockquote>
  <p>So i have this module, used from another application. It's composed of other submodules and i want to configure it using a configuration object.
  I already tried to inject the configuration in my submodels but i had the same problem exposed in the original question.</p>
  <p>For example my module use mongoDB (with mongoose) as a store.</p>
  <pre><code>// app.js
  // in the config object i have the URI to the mongo instance (in order to create a connection).
  var myModule = require('myModule')(config);
  
  // myModule.js
  // files
  // myModule/index.js expose the module's functionalities
  // is the entry point so I create the mongoose connection
  var mongoose = require('mongoose');
  module.exports = function(config){
    var connection = mongoose.createConnection(config.store.URL);
    // I need to expose this connection to the others submodules.
  }
  
  // myModule/storeController.js contains the business logic that use the store (createItem, deleteItem, get...) and requrie mongoose and my Models (store in the models folder)
  var mongoose = require('mongoose');
  var Item     = require('./models/item.js');
  
  exports.createItem = function(item){
    Item.save(item, function(err, item){
      if (err) throw
      ...
    });
  } 
  
  // myModule/models/item.js
  
  // In this module i need to use the connection application in the configuration.
  var mongoose = require('mongoose');
  var connection = // i don't know how to get it
  
  var ItemSchema = new mongoose.Schema({
    name: String
  });
  
  module.exports = mongoose.model('item', ItemSchema);
  </code></pre>
  <p>If I inject the configuration obj to the item.js i can't do the module.exports of my model.
  I hope that this example can clarify my question, but the problem is the simple, expose an object after get it as a parameter.</p>
  <p>[PREVIOUS]
  I have a node.js application that require a module. This module accept the coniguration file path (a JSON file).
  I need to load that configuration on require and expose it to the module.</p>
  <p>How can I achieve this behavior?</p>
  <p>Something like:</p>
  <pre><code>// app.js
  var myModule = require('myModule')(__dirname + '/config/myModuleCnfig.json');
  
  // myModule.js
  
  module.exports = function(configPath){
    var config = require(configPath);
    module.exports = config;  // This is wrong
  }
  </code></pre>
  <p>Is there another way to get the configuration path, configure the module and share the configuration??</p>
  <p>With &quot;share the configuration&quot; i mean that i want to give the possibility to other files of my module to use that configuration.</p>
  <p>Thanks for any suggestions!</p>