There are so many different ways to deploy a node app around the internet. Here’s my way.
- Use git for version control
Install forever – this allows handling of the node process. It’s better than running it in a screen session like most people do!
sudo npm install -g forever
Allow the git user account (which should be unprivileged) to host on port 80. After following this guide I decided to use setcap:
sudo apt-get install libcap2-bin
sudo setcap ‘cap_net_bind_service=%2Bep’ /usr/local/bin/node
Add a post-receive hook on the remote (bare) repositiory to check out and restart the node process using forever. For example:
git checkout -f
forever stop dspa-server.js
forever start dspa-server.js
That’s it! Simply push to the server to update and restart the node instance.
Also a convention is to use an environment variable to define the port. This is most useful when a proxy is used (for example, to use apache). This is used, for example, to work with the cloud9 ide.