There are so many different ways to deploy a node app around the internet. Here’s my way. A way I no longer use.
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!1
sudo npm install -g forever
CopyAllow 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
CopyAdd a post-receive hook on the remote (bare) repository to check out and restart the node process using forever. For example:
#!/bin/bash
export GIT_WORK_TREE=/home/naggie/dspa/
git checkout -f
cd $GIT_WORK_TREE
forever stop dspa-server.js
forever start dspa-server.js
CopyThat’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.
Nowadays I recommend installing a systemd service. ↩︎
Thanks for reading! If you have comments or like this article, please post or upvote it on Hacker news, Twitter, Hackaday, Lobste.rs, Reddit and/or LinkedIn.
Please email me with any corrections or feedback.