Published:
If you configure your Github repository to use webhooks, you can deploy code to a server by simply pushing it to Github. When you push code to Github, a Github webhook push event occurs. You can listen for these Github webhook push events in your node.js program with the help of github-webhook-deployer. github-webhook-deployer listens for Github push events. When one occurs, it runs git pull; npm install and kills the current process. By starting the process using a daemon manager, such as Forever.js, the process is restarted and you have deployed new code to a server with a git push.
First, install nodejs if you haven't already. Then create a directory to contain your project code. My example is Blog - a simple webapp hosting this page. Inside the new directory, run
#Initialize your project
npm init
Next, add dependencies to your project. We'll be using github-webhook-deployer and websocket-express. Here is the resulting package.json.
Now, the blog code (index.js)
Finally, to run the code
forever start index.js 3000