Simple node app deployment

Nov 2012 - 1 min read

There are so many different ways to deploy a node app around the internet. Here’s my way. A way I no longer use.

  1. Use git for version control

  2. 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
  3. 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
  4. Add a post-receive hook on the remote (bare) repository to check out and restart the node process using forever. For example:

     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.

  1. 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,, Reddit and/or LinkedIn.

Please email me with any corrections or feedback.