Auto run a node.js app on when your EC2 server starts up

Posted by Derek McAuley on June 3rd, 2017

I have a node.js app on an EC2 server but when the server restarts(which it does every two days) the app wasn't starting with it.
I've found an easy solution
By editing the '/etc/rc.local' file you can run a file each time the server starts.

SSH into your server.

Type the below commands:

nano /etc/rc.local

Add the below text:
Replace index.js with your apps name(appname.js)

/home/ubuntu/.nvm/versions/node/v7.7.2/bin/node /home/ubuntu/index.js

To find the location of your node folder type the below command(mine is here '/home/ubuntu/.nvm/versions/node/v7.7.2/bin/node') :

which node
Which command for node

Below is what the file should look like.

Adding the boot command

Press CTL and X to exit the editor, type 'y' to save and then just press enter when prompted with the file name.

Now restart the server:

sudo roboot

Your app will now run each time the server reboots

“You should always waste time when you don't have any. Time is not the boss of you. Rule 408.”



Why not leave a comment below.


Name:

Comments:




Comments:

No comments yet, why not be the first