Simple use case - deploy your updated Node.js app on a push to a GitHub repository. To achieve this, we will use several tools:
All source code with example Node.js server and configuration can be found here: https://github.com/webhookrelay/webhook-autoupdate.
First things first, let’s clone the repository:
Now, let’s get the tooling.
Now, install webhook. If you have a working Go environment, you can just do
go get github.com/adnanh/webhook, otherwise go to the https://github.com/adnanh/webhook/releases page and grab the one that suits your operating system. If you have a casual Linux machine, you probably want webhook-linux-amd64.tar.gz while MacOS users should choose webhook-darwin-amd64.tar.gz. Download, extract and put it in your PATH or just this repository.
My webhook-autoupdate repository holds
hooks.json configuration file which should be supplied to the
webhook app. First, edit the hooks JSON file with the correct path to command and working directory. Current one is
Update marked fields to something that reflects the path to where you have currently cloned this repository.
Once you did that, start it:
Start relay agent:
Grab that public endpoint and head to your GitHub repository settings page:
Then, add public Webhook Relay endpoint and set “secret” the same one as in your hooks.json (in example file it’s
"secret": "verysecret") and content type
While in the repository, install dependencies:
Time to start our node app:
That’s it! If you push new changes to the GitHub repository, it will send a webhook that will trigger an update.
When you push to the repository, in
nodemon terminal you should see:
and in webhook relay bucket you should see request logs:
If you refresh the browser window http://localhost:8080, you will see the new code running.
Interested or working with webhooks? Check out how you can receive webhook on localhost or private networks in our examples collection. Webhook Relay has a free tier for developers!