How can I watch a github branch from nodejs?

I have a node process and I would like it to perform certain tasks when a specific GitHub branch is updated on a repository I own. I would also like to obtain a list of the changed files, but this can go into a separate question in due time. For now, if I could find a way to implement something like this, I would be very happy:

In my node process

var watched = new gitBranch('https://github.com/me/myOwnRepository#production')
watched.on('update', function () {
  console.log('new commit on my production branch')
})

I suppose I could poll the repo using the GitHub API, but I don't see anything in the GitHub API about fetching only a certain branch. Also, I would certainly prefer some sort of notification to polling, but again I haven't found anything like this for branches.

Any ideas?

Use webhooks: https://developer.github.com/webhooks/

The push event is what you'll be interested in: https://developer.github.com/v3/activity/events/types/#pushevent

Notice that the payload contains a "ref" attribute which tells you which branch was pushed to. Use that to do the filtering on your end (it's not possible to subscribe for events on a specific branch).