title: How npm install works
body: <p>I use Node.js (via <a href="https://github.com/substack/node-browserify">browserify</a>) for each of my web apps, all of which have some dependencies in common and others specific to themselves. Each of these apps has a <code>package.json</code> file that specifies which versions of which modules it needs.</p>
  
  <p>Right now, I have a <code>/node_modules</code> directory in the parent folder of my apps for modules that they all need to reference, and then I put app-specific modules in a <code>node_modules</code> folder in that app's directory. This works fine in the short term, since my <code>require()</code> statements are able to keep looking upward in the file structure until they find the <code>node_modules</code> directory with the correct app in it.</p>
  
  <p>Where this gets tricky is when I want to go back to an old project and run <code>npm install</code> to make sure it can still find all the dependencies it needs. (Who knows what funny-business has occurred since then at the parent directory level.) I was under the impression that <code>npm install</code> did this:</p>
  
  <ul>
  <li>for each module listed in <code>package.json</code>, first check if it's present, <strong>moving up the directory the same way <code>require</code> does</strong>. If it's not, install it to the local <code>node_modules</code> directory (creating that directory if necessary).</li>
  </ul>
  
  <p>When I run <code>npm install</code> inside an app folder, however, it appears to install everything locally regardless of where else it may exist upstream. Is that the correct behavior? (It's possible there's another reason, like bad version language in my <code>package.json</code>). If this IS the correct behavior, is there a way for me to have <code>npm install</code> behave like the above?</p>
  
  <p>It's not a big deal to widely replicate the modules inside every app, but it feels messy and prevents me from make small improvements to the common modules and not having to update every old <code>package.json</code> file. Of course, this could be a good thing...</p>