title: Node.js dynamic relative require path
body: <p>I need to be able to use require() on a dynamic relative path - meaning that the relative path needs to change depending on the current environment.</p>
  
  <p>What is the best practice for this type of situation?</p>
  
  <p>I thought of something like this:</p>
  
  <pre><code>var module = require(process.env.MY_MODULES_PATH + '/my-module');
  </code></pre>
  
  <p>However environment variables are not very convenient.</p>
  
  <p>Are there other possibilities? </p>
  
  <ul>
  <li>Maybe use package.json post-install script to set the environment variable for me?</li>
  <li>Maybe there's a built in solution in node I don't know about?</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>I just realized that this is a special case of <code>require()</code> "mocking". Is there a best practice for how to mock <code>require()</code> for unit-tests for example?</p>