How do I load a node module as if the current module were located somewhere else? : <p>I have some nodejs code running in a module somewhere. From this module, I would like to load a module located in a completely different place in the file system -- for example, given the path <code>"/another/dir"</code> and the module name <code>"foo"</code>, I would like Node to act as if a module running in <code>/another/dir</code> had called <code>require("foo")</code>, rather than my own module.</p>

<pre><code>  My code is running here
/some/folder/node_modules/mine/my_module.js

  I have the path "/another/dir/", the string "foo",
    and want to load this module
/another/dir/node_modules/foo/index.js
</code></pre>

<p>In other words, the <a href="https://nodejs.org/api/modules.html#modules_all_together" rel="noreferrer">module documentation</a> refers to the process <em>"require(X) from module at path Y"</em>, and I would like to specify my own value for <code>Y</code></p>

<p>Can this be accomplished? If so, how? If not, why not?</p>
