Installing Multiple Node Apps on VPS
This is my version, after setting up apache and nginx together on the same instance.
nvm (node version manager), and also
The example use nvm version 0.7.0. You can update accordingly.
1 2 3 4
1 2 3 4
Finally, you probably want to copy the active version into
Deploying your app
I have choose to deploy using SFTP.
I use Cyberduck (Mac app), and simply copy the node app into eg
Note: There are better ways. And using dokku seems to be very popular, but dokku does not support running multiple apps.
If you followed the tutorial in setting up apache alongside nginx, you would want to edit the server block for the node app like this (I have changed the name to
nodeapp instead of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Restart nginx with
sudo service nginx restart.
Install Forever (Globally)
Forever is to ensure your node app gets run forever. That means if it crashes, it will restart for you.
Start with Forever
1 2 3 4 5 6 7 8
Start with Forever, truly forever
Your app is not truly running forever.
If your VPS crash, then forever is not being started..
Hence, you need a cronjob and this
starter.sh in your home folder. You can
nano ~/starter.sh and copy the following:
1 2 3 4 5 6 7
crontab -e, and add the following:
To know where your path to
starter.sh is, use
pwd at the directory.
To test your script is correct, you can:
1 2 3 4 5 6
Or reboot your VPS to see that it gets truly run forever and ever :)
Multiple Node Apps
To deploy multiple node apps, repeat (except for installing node, git, forever, crontab).
Assuming I have another app call
nodeapp2, these are the changes:
/var/www/nodeapp2.com/– contains the node app
nodeapp2.com.conf– for nginx configuration (with a different port)
starter.sh– add another line for the new node app to forever start