user1056805
user1056805

Reputation: 2933

How do I setup a node server so that I can push updates with git?

If I'm hosting my own node.js server, how would I go about making it so that I can push updates to the code like I would on Heroku?

I want to be able to host my source code on the same server as my node app and then whenever I push updates, it will restart the node app with the updated code. How do I do this?

Thanks!

Upvotes: 0

Views: 78

Answers (1)

Yannick Blondeau
Yannick Blondeau

Reputation: 9621

You should use a git post-receive hook.

From the documentation:

The post-receive hook runs after the entire process is completed and can be used to update other services or notify users.

Your script could be something like

  • Stop your node app
  • Copy new files over old ones
  • Restart node app

Be aware that your script should not take a long time to run as

This script can’t stop the push process, but the client doesn’t disconnect until it has completed; so, be careful when you try to do anything that may take a long time.

Upvotes: 1

Related Questions