title: npm-start not running in aws cloudformation user data
body: <p>I'm trying to run npm start in aws cloudformation user data like this:</p>
  
  <pre><code>nodejs = '\n', \
               'echo "starting node server" &gt; /tmp/nodejs.log\n', \
               'npm run start-dev --prefix /data/app/myProject &gt;&gt; /tmp/nodejs.log &amp;\n', \
               'echo "After starting node server" &gt;&gt; /tmp/nodejs.log', \
               '\n' ''
  </code></pre>
  
  <p>This is later put into userdata along with other commands.</p>
  
  <p>Here is what I get in /tmp/nodejs.log after execution:</p>
  
  <pre><code>starting node server
  After starting node server
  </code></pre>
  
  <p>The npm run command doesn't leave any logs and the server isn't started. If I run that command in the terminal then the server would run successfully.</p>
  
  <p>Why isn't the npm-start command being executed? </p>
  
  <p><strong>Follow up</strong></p>
  
  <p>The reason the server isn't starting is because the npm command isn't recognized in the userdata script. I am however installing node via nvm in a packer provisioner script:</p>
  
  <pre><code>{
    "type": "shell",
    "script": "sh/install_node.sh",
    "execute_command": "chmod +x {{ .Path }}; sudo bash -c '{{ .Vars }} {{ .Path }}'"
  }
  </code></pre>
  
  <p>Here's the install_node.sh file:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  #install nvm
  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
  
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] &amp;&amp; \. "$NVM_DIR/nvm.sh"  # This loads nvm
  [ -s "$NVM_DIR/bash_completion" ] &amp;&amp; \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  
  #install node
  nvm install 6.8.0
  </code></pre>
  
  <p>So now I'm trying to figure out why installing node via a packer provisioner script isn't enough for npm to be recognized in aws cloudformation userdata script.</p>