title: How to run a post-install script after individual execution of "npm install <package>"
body: <p>I am maintaining the following directory structure:</p>
  
  <pre><code>/home/user/Desktop/
                   |-- app/
                   |      |-- package.json
                   |      `-- server.js
                   |-- node/
                   |      |-- bin/
                   |      |      |-- node
                   |      |      `-- npm
                   |      |-- include/
                   |      |-- lib/
                   |      `-- share/
                   |
                   `-- npm.sh
  </code></pre>
  
  <p>I want all my locally installed node modules reside in the directory <strong><code>node</code></strong>. That is, if I run <code>npm install</code> inside the directory <code>app</code>, initially it'll install the modules inside the current directory (<code>app</code>) and then move the <code>node_modules</code> folder to the external directory called <code>node</code>. For this purpose I've written a script <code>npm.sh</code> and placed the <code>mv</code> (move) command inside the <code>postinstall</code> script of <code>package.json</code>.</p>
  
  <p>These are the files <code>npm.sh</code> and <code>package.json</code>.</p>
  
  <p>content of <strong><code>npm.sh</code></strong>:</p>
  
  <pre><code>#/bin/bash
  
  export PATH=/home/user/Desktop/node/bin:$PATH
  export NODE_PATH=/home/user/Desktop/node/node_modules
  export NODE_MODULE_ROOT=/home/user/Desktop/node
  /bin/bash
  </code></pre>
  
  <p>content of <strong><code>app/package.json</code></strong>:</p>
  
  <pre><code>{
    "name": "app",
    "version": "1.0.0",
    "scripts": {
      "postinstall": "mv node_modules $NODE_MODULE_ROOT",
      "start": "node server.js"
    },
    "dependencies": {
      "jwt-simple": "^0.5.1"
    }
  }
  </code></pre>
  
  <p>But the problem is: when I do <code>./npm.sh &amp;&amp; cd app &amp;&amp; npm install</code>, everything works as intended. But when I do <code>npm install jwt-simple</code>, the <code>postinstall</code> script is not getting executed.</p>
  
  <p>Is there a way to make it work for individual <code>npm install &lt;package&gt;</code> ? Or is there any better way to accomplish this ?</p>