title: Project root based relative paths for NodeJS modules
body: <p>Dealing with module inclusion in my NodeJS projects I always struggle a bit in the way of specifying paths to other module files of the project to be required.</p>
  
  <p>I obviously use relative paths. But this implies doing things like:</p>
  
  <pre><code>const helper = require("../../lib/util/helpers.js
  </code></pre>
  
  <p>This has some drawbacks:</p>
  
  <ol>
  <li><p>I always need to take in account where the file from which I requiring another module is placed.</p></li>
  <li><p>As the project grows I occasionally need to move some files to another place due to project restructuring so I need to review not only paths from files requiring it, but also the paths of all modules required in the file I am moving.</p></li>
  </ol>
  
  <p>I always thought it would be much clearer if I could specify paths relative to the project root instead of the file itself. To be clear, that is where my <code>package.json</code> file (or <code>node_modules</code> directory) is placed.</p>
  
  <p>I know I can resolve the path of any external module using <code>require.resolve()</code> and I though I could do something like <code>path.dirname(path.dirname(path.dirname(require.resolve('express'))))</code> but it seems too dirty to me.</p>
  
  <p>Unfortunately, as far as I know, there isn't any <code>require.modules_path</code> or <code>require.projectRoot</code> property so I need to rely on some trick like that I mentioned above or traversing the whole tree up to the first parent directory containing a <code>package.json</code> file.</p>
  
  <p>My question is: Is there any better solution which I am missing?</p>