title: NodeJS on production server - permissions
body: <p>I want to have <code>node</code> and <code>npm</code> available for whatever user is on the system. </p>
  
  <p>In our team, when someone updates code from git they run:<code>sudo -u www-data git pull</code></p>
  
  <p>So whatever project it is, we always go through <code>www-data</code> user. </p>
  
  <p>Now we have new Node project and need to do the same. There is no way that on our production server we will rely on one user handling everything about node - what if he leaves tomorrow?</p>
  
  <p>So we are not using NVM, but installing Node as a root as <a href="https://github.com/nodejs/node-v0.x-archive/wiki/Installing-Node.js-via-package-manager#debian-and-ubuntu-based-linux-distributions" rel="noreferrer">described here</a></p>
  
  <p>Its all fine, and all users see <code>node</code> and <code>npm</code> executable. Problems start when we actually try to use them.</p>
  
  <p>What you want to do is:</p>
  
  <pre><code>cd /var/www/node_project
  sudo -u www-data git pull
  sudo -u www-data npm install
  </code></pre>
  
  <p>This fails on last command, because <code>npm</code> is trying to write <code>lock</code> file in my home directory. So:<code>/home/user/.npm</code> instead of somewhere globally or <code>/var/www/.npm</code> which would be home directory for www-data user.</p>
  
  <p>Similar to that, after installing </p>
  
  <p><code>sudo npm install -g typings</code></p>
  
  <p>And then running <code>sudo -u www-data typings install</code> you get an error, because it is trying to write <code>/home/user/.config/configstore/insight-typings.json</code></p>
  
  <p>Could someone please elaborate how to actually properly install node on server? If I run <code>sudo -u www-data</code> how come npm ins still going into my home folder?</p>