npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

github-webhook

v3.0.6

Published

A flexible web server for reacting GitHub Webhooks

Readme

github-webhook

NPM

A lightweight server that listens for GitHub Webhook events and executes commands when specific conditions are matched. Useful for automated deployments, CI triggers, and other GitHub-driven workflows.

Installation

npm install -g github-webhook

Quick Start

github-webhook \
  --port=9999 \
  --path=/webhook \
  --secret=mygithubsecret \
  --rule='push:ref == "refs/heads/master" && repository.name == "myrepo":./deploy.sh'

Then configure your GitHub repository's webhook settings to point to http://yourserver:9999/webhook with the matching secret.

Configuration

You can configure github-webhook via command-line arguments or a JSON config file (or both - command-line overrides the config file).

Command-line

github-webhook \
  --config=/etc/github-webhook.json \
  --port=9999 \
  --path=/webhook \
  --secret=mygithubsecret \
  --log=/var/log/webhook.log \
  --rule='push:ref == "refs/heads/master":./deploy.sh'

Config file

{
  "port": 9999,
  "path": "/webhook",
  "secret": "mygithubsecret",
  "log": "/var/log/webhook.log",
  "rules": [
    {
      "event": "push",
      "match": "ref == \"refs/heads/master\" && repository.full_name == \"myuser/myrepo\"",
      "exec": "/var/www/deploy.sh"
    }
  ]
}

Options

| Option | Required | Description | |--------|----------|-------------| | port | Yes | Port to listen on (also respects PORT env var) | | path | Yes | URL path to receive webhooks (e.g., /webhook) | | secret | Yes | Webhook secret for payload verification (configure the same value in GitHub) | | host | No | Bind to a specific host/IP address | | log | No | Log file path, or stdout/stderr for console output | | rules | No | Array of rules to match and execute (see below) |

Rules

Rules define what commands to execute when specific webhook events are received.

Rule properties

| Property | Description | |----------|-------------| | event | GitHub event type to match (push, pull_request, issues, etc.). Use * to match all events. See GitHub Webhooks documentation for available events. | | match | Expression to match against the webhook payload. Uses matchme syntax. | | exec | Command to execute. A string runs via sh -c "...". An array executes directly (first element is the command, rest are arguments). |

Command-line rule syntax

Rules can be specified on the command line as --rule 'event:match:exec':

--rule 'push:ref == "refs/heads/master":./deploy.sh'

Environment variables

Commands receive the entire webhook payload as environment variables with a gh_ prefix:

  • gh_ref - The git ref (e.g., refs/heads/master)
  • gh_branch - The branch name (extracted from ref for convenience)
  • gh_repository_name - Repository name
  • gh_repository_full_name - Full repository name (e.g., owner/repo)
  • gh_sender_login - Username of the person who triggered the event
  • ... and all other payload fields

Nested objects become underscore-separated (e.g., gh_repository_owner_login).

Example rules

Deploy on push to master:

{
  "event": "push",
  "match": "ref == \"refs/heads/master\" && repository.full_name == \"myuser/myrepo\"",
  "exec": "/var/www/deploy.sh"
}

Run tests on pull request:

{
  "event": "pull_request",
  "match": "action == \"opened\" || action == \"synchronize\"",
  "exec": ["./run-tests.sh", "--pr"]
}

Log all events:

{
  "event": "*",
  "match": "true",
  "exec": "echo \"Received $gh_event\" >> /var/log/webhooks.log"
}

Running as a Service

systemd (recommended)

Create /etc/systemd/system/github-webhook.service:

[Unit]
Description=GitHub Webhook Server
After=network.target

[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/github-webhook --config /etc/github-webhook.json
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Then enable and start:

sudo systemctl daemon-reload
sudo systemctl enable github-webhook
sudo systemctl start github-webhook
sudo systemctl status github-webhook

View logs:

sudo journalctl -u github-webhook -f

Running behind a reverse proxy

For production, run github-webhook behind nginx or another reverse proxy that handles TLS:

location /webhook {
    proxy_pass http://127.0.0.1:9999;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}

Then configure github-webhook with --host=127.0.0.1 to only accept local connections.

Programmatic Usage

import webhook from 'github-webhook'

const server = webhook({
  port: 9999,
  path: '/webhook',
  secret: 'mygithubsecret',
  rules: [
    {
      event: 'push',
      match: 'ref == "refs/heads/master"',
      exec: './deploy.sh'
    }
  ]
})

server.listen(9999, () => {
  console.log('Webhook server listening on port 9999')
})

The function returns an http.Server instance with an attached webhookHandler for custom event handling:

server.webhookHandler.on('push', (event) => {
  console.log('Push event:', event.payload)
})

Debugging

Enable debug output with the DEBUG environment variable:

DEBUG=github-webhook:* github-webhook --config /etc/github-webhook.json

More Information

github-webhook is powered by github-webhook-handler.

License

github-webhook is Copyright (c) 2015 Rod Vagg and licensed under the MIT License. All rights not explicitly granted in the MIT License are reserved. See the included LICENSE.md file for more details.