Simple node app deployment with git and forever
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
Copysudo npm install -g foreverAllow the git user account (which should be unprivileged) to host on port 80. After following this guide I decided to use setcap:
Copysudo apt-get install libcap2-bin sudo setcap 'cap_net_bind_service=%2Bep' /usr/local/bin/nodeAdd a post-receive hook on the remote (bare) repository to check out and restart the node process using forever. For example:
Copy#!/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
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.
Nowadays I recommend installing a systemd service. ↩︎
Thanks for reading! If you enjoyed this article or have comments, please consider sharing it on Hacker news, Twitter, Hackaday, Lobste.rs, Reddit and/or LinkedIn.
You can email me with any corrections or feedback.
Tags:
Related: