npm install causing “No space left on device” Pivotal Cloud Foundry

Had an issue while deploying to a 2GB Pivotal Cloud Foundry instance during npm install buildpack step. My instance was limited to 2GB disk space, but somehow my 100mb application was filling up the drive.

Error was along the lines of:

cp: cannot create directory ‘/tmp/contents258369199/...’: No space left on device

Turns out npm’s package cache is on by default, and was saving all installed packages to a cache directory on disk. So if you’re limited on disk space during a build, turn this off with the environment variable:

NODE_MODULES_CACHE=false

Elastic Beanstalk npm install error EACCES: permission denied, mkdir ‘/home/webapp’

Ran into an error while deploying to an AWS Elastic Beanstalk instance set up for Rails + Node + Webpack.

Full error during npm install:

npm install
npm ERR! Linux 4.4.23-31.54.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/support/node-install/node-v4.6.0-linux-x64/bin/node" "/usr/bin/npm" "install"
npm ERR! node v4.6.0
npm ERR! npm  v2.15.9
npm ERR! path /home/webapp
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/home/webapp'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/home/webapp']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/webapp',
npm ERR!   parent: 'testing-app' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

After some Googling, this Stack Overflow thread gave me some clues: Deploying a Rails / Ember app on AWS Elastic Beanstalk

The /home/webapp directory needed to be created during deploy. This was accomplished using a .ebextensions config with a commands stanza. Docs on commands here

The final commands I used are as follows:

commands:
  01_mkdir_webapp_dir:
    command: mkdir /home/webapp
    ignoreErrors: true
  02_chown_webapp_dir:
    command: chown webapp:webapp /home/webapp
    ignoreErrors: true
  03_chmod_webapp_dir:
    command: chmod 700 /home/webapp
    ignoreErrors: true