1

I started an Amazon Linux instance via AWS EC2. I'm trying to write an upstart script that will start my node server when the instance starts up.

If I run npm start in the terminal, my node server starts successfully. I'm using the following upstart script, but it doesn't start my server.

# Upstart Script for My Server
description "my-server"

start on started mountall
stop on shutdown

# Automatically Respawn
respawn
respawn limit 99 5

# Environment Variables
env NODE_ENV=development

# Script to Start Server
script
  cd /home/ec2-user/my-server
  exec /usr/bin/npm start >> /var/log/my-server.log 2>&1
end script

Checking the /var/log/my-server.log file tells me /user/bin/npm: No such file or directory.

Derek Soike
  • 11,238
  • 3
  • 79
  • 74

1 Answers1

1

My issue was due to the fact that I had installed node using NVM (Node Version Manager). NPM was not installed in my /user/bin directory. I just needed to find where it was installed by NVM.

# Script to Start Server
# - Referencing 'npm' from Node Version Manager (NVM) install location.
script
  cd /home/ec2-user/my-server
  exec /home/ec2-user/.nvm/versions/node/v4.4.5/bin/npm start >> /var/log/my-server.log 2>&1
end script
Derek Soike
  • 11,238
  • 3
  • 79
  • 74