PM2 can be used to manage and run application in production. For this article we are going to use Ubuntu 14.04.2 LTS. But it should work on Amazon linux or any other Linux with minor changes. Login to your system using user ubuntu (or the user you want to use for running pm2).

Install node and pm2

In case you have not installed node, npm and pm2 you can install these using the following instructions:

Note the presence of user ubuntu in /etc/init.d/pm2-init.sh (you can use some other user also).
Now save the current state (assuming hello.js is still running with name hello-app)

$ pm2 save
[PM2] Dumping processes
$ cat ~/.pm2/dump.pm2

The processes are dumped in file ~/.pm2/dump.pm2. Now when you reboot the machine, the PM2 daemon with start and it will then start all processes managed by it. Note that pm2 resurrect uses data saved in ~/.pm2/dump.pm2 to start various processes. In case pm2 dies for some reason, you can run pm2 resurrect manually also.

Deleting an app

To delete a running app managed by pm2 run this:

pm2 delete hello-app

You can also look at more documentation about pm2 various commands at pm2 Advanced README on github.