title: Node.js require path stored in a variable
body: <p>I am testing some nodejs code, and this is how my directory looks like:</p>
  <pre><code>-&gt; source  //NODE PATH=./source ...
  -&gt; plugs
     -myPlug.js
     -test.js
  </code></pre>
  <p>In <code>test.js</code> I try to require <code>myPlug.js</code> like this:</p>
  <pre><code>function(){
       var myRequiredPlug = require('./myPlug.js') //this works
  }
  </code></pre>
  <p>Since the <code>NODE PATH</code> is <code>source</code>, I have also tried:</p>
  <pre><code>function(){
       var myRequiredPlug = require('./../plugs/myPlug') //also works
  }
  </code></pre>
  <p>But I will have to require a different plug every time for my app, so I would very much like to create the path this way:</p>
  <pre><code> function(nameOfPlug){  // nameOfPlug := myPlug
       var myPath = './../plugs/' + nameOfPlug;
       console.log(myPath === './../plugs/myPlug') // true, so same string
       var myRequiredPlug = require(myPath);  
  }
  </code></pre>
  <p>When I try it his way, I get the error: <code>Error: Cannot find module './../plugs/myPlug'</code></p>
  <p>I have already tried <code>path.normalize</code>, and even to join the paths with <code>path.join</code>, but get the same results. Any ideas?</p>
  <h2>Update: Answer</h2>
  <p>This answer can be solved using <em>RequireJS</em>, <a href="https://stackoverflow.com/questions/17446844/dynamic-require-in-requirejs-getting-module-name-has-not-been-loaded-yet-for-c">Dynamic require in RequireJS, getting &quot;Module name has not been loaded yet for context&quot; error?</a></p>