title: How to automatically link npm packages at installation time?
body: <p>I'm working on a larger project that is split into a number of <strong>npm</strong> packages. There are several dependencies between the packages. The whole code base is stored in a main directory like this:</p>
  
  <pre><code>main/
    pkg1/
    pkg2/
    ...
  </code></pre>
  
  <p>Suppose that <em>pkg2</em> depends on <em>pkg1</em>, so in <code>main/pkg2/package.json</code> I have:</p>
  
  <pre><code>"dependencies": {
    "pkg1": "^0.1.0"
  }
  </code></pre>
  
  <p>I have linked my packages together using <code>npm link</code>. However when I start development on a new machine or for some reason I have to reinstall the packages I can't simply say <code>npm install</code> in <code>pkg2/</code>. It would fail because <code>pkg1</code> couldn't be found. (It's not published, but anyway, I want the local version because I'm developing both packages).</p>
  
  <p>Of course I can do all the linking manually than call <code>npm install</code> but it's a hassle. Is there any way to do it in a single step?</p>
  
  <p><em>My previous research:</em></p>
  
  <p><a href="https://stackoverflow.com/questions/38855927/npm-link-done-at-install-time-inside-package-json">This</a> question proposes writing a <em>preinstall</em> script, but I don't want to keep linking in production, only in the development environment, as <a href="https://stackoverflow.com/a/20529986/2599894">another</a> answer points it out.</p>
  
  <p>I've also tried <code>npm link</code> in <code>pkg1/</code> then <code>npm install --link</code> in <code>pkg2/</code>. According to the manual,</p>
  
  <blockquote>
    <p>The --link argument will cause npm to link global installs into the local space in some cases.</p>
  </blockquote>
  
  <p>Not in my case though.</p>