title: Error: EACCES: permission denied when running `npm install` on Elastic Beanstalk
body: <p>I've provisioned a default clean node.js app via Elastic Beanstalk, and have a node.js script trying to run <code>npm install</code> inside the project directory (<code>/var/app/current/deploy-dist</code>), however, the following permission error is thrown:</p>
  
  <pre><code>npm WARN locking Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
  npm WARN locking     at Error (native)
  npm WARN locking  /tmp/.npm/_locks/staging-f212e8d64a01707f.lock failed { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
  npm WARN locking     at Error (native)
  npm WARN locking   errno: -13,
  npm WARN locking   code: 'EACCES',
  npm WARN locking   syscall: 'open',
  npm WARN locking   path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
  npm WARN deploy-dist No description
  npm WARN deploy-dist No repository field.
  npm WARN deploy-dist No license field.
  npm ERR! Linux 4.4.35-33.55.amzn1.x86_64
  npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/npm" "install"
  npm ERR! node v6.9.1
  npm ERR! npm  v3.10.8
  npm ERR! path /tmp/.npm/_locks/staging-f212e8d64a01707f.lock
  npm ERR! code EACCES
  npm ERR! errno -13
  npm ERR! syscall open
  
  npm ERR! Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
  npm ERR!     at Error (native)
  npm ERR!  { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
  npm ERR!     at Error (native)
  npm ERR!   errno: -13,
  npm ERR!   code: 'EACCES',
  npm ERR!   syscall: 'open',
  npm ERR!   path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
  npm ERR!
  npm ERR! Please try running this command again as root/Administrator.
  
  npm ERR! Please include the following file with any support request:
  npm ERR!     /var/app/current/deploy-dist/npm-debug.log
  </code></pre>
  
  <p>The <code>package.json</code> is just a:</p>
  
  <pre><code>{
    "dependencies": {
      "node-fetch": "^1.3.3"
    }
  }
  </code></pre>
  
  <p>Running <code>npm install</code> with sudo obviously works, but is preferred to be avoided as a solution.</p>
  
  <p>Setting <code>NPM_CONFIG_PREFIX</code> to a directory at <code>~</code> as per <a href="https://docs.npmjs.com/getting-started/fixing-npm-permissions" rel="noreferrer"><code>npm</code> docs suggestion</a> didn't work either, and the problem persists.</p>
  
  <p>I suspect the problem lies in incorrect permissions for <code>/tmp/.npm</code>, which are</p>
  
  <pre><code>drwxr-xr-x 114 root root 4.0K Dec 27 17:04 .npm
  </code></pre>
  
  <p>This is confusing, as I expected a simple <code>npm install</code> to work out of the box.</p>
  
  <p><strong>UPDATE:</strong> Should not that the project directory already contains a <code>node_modules</code> folder, but even removing it and running <code>npm install</code> doesn't fix it.</p>