{"id":18332,"library":"express-github-webhook","title":"express-github-webhook","description":"A lightweight Express middleware for handling GitHub Webhooks, version 1.0.6. It validates webhook signatures using a secret, parses event payloads, and emits events for easy integration. Unlike alternatives like `github-webhook-handler`, this package is designed specifically for Express and requires body-parser. Release cadence is low; last update was years ago, but the package is stable for basic use cases.","status":"maintenance","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/gisonrg/express-github-webhook","tags":["javascript","github","webhook","express","middleware"],"install":[{"cmd":"npm install express-github-webhook","lang":"bash","label":"npm"},{"cmd":"yarn add express-github-webhook","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-github-webhook","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to parse JSON request bodies before the middleware runs","package":"body-parser","optional":false}],"imports":[{"note":"This package is CJS-only; no ESM support.","wrong":"import { GithubWebHook } from 'express-github-webhook';","symbol":"GithubWebHook","correct":"const GithubWebHook = require('express-github-webhook');"},{"note":"GithubWebHook is a factory function, not a constructor. Do not use 'new'.","wrong":"const webhookHandler = new GithubWebHook();","symbol":"webhookHandler","correct":"const webhookHandler = GithubWebHook({ secret: 'mysecret' });"},{"note":"For named events (not '*'), callback signature is (repo, data). The 'event' parameter is omitted.","wrong":"webhookHandler.on('push', function(event, repo, data) { ... });","symbol":"on","correct":"webhookHandler.on('push', function(repo, data) { ... });"}],"quickstart":{"code":"const express = require('express');\nconst bodyParser = require('body-parser');\nconst GithubWebHook = require('express-github-webhook');\n\nconst app = express();\napp.use(bodyParser.json());\n\nconst webhookHandler = GithubWebHook({ path: '/webhook', secret: process.env.GITHUB_SECRET ?? '' });\napp.use(webhookHandler);\n\nwebhookHandler.on('push', function(repo, data) {\n  console.log('Push event on repo:', repo);\n  console.log('Payload:', data);\n});\n\nwebhookHandler.on('*', function(event, repo, data) {\n  console.log(`Any event ${event} on repo ${repo}`);\n});\n\napp.listen(3000, () => console.log('Server listening on port 3000'));","lang":"javascript","description":"Sets up an Express server with body-parser and the GitHub webhook middleware, listens for push events and wildcard events."},"warnings":[{"fix":"Use require() instead of import.","message":"The package is CJS-only; it cannot be imported using ESM syntax (import). Use require() to avoid errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call GithubWebHook(options) without new.","message":"GithubWebHook is a factory function, not a constructor. Calling new GithubWebHook() will throw an error.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the correct signature: webhookHandler.on('push', function(repo, data) { ... });","message":"Event listeners for specific events (e.g., 'push') have a different callback signature from the wildcard '*' event. For specific events, the callback is (repo, data). For '*', it is (event, repo, data).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure app.use(bodyParser.json()) is called before app.use(webhookHandler).","message":"The package requires body-parser to be used before the middleware. If body-parser is not applied, the middleware will not parse the payload.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use express.json() instead of body-parser: app.use(express.json());","message":"body-parser is deprecated in favor of express's built-in express.json() since Express 4.16.0. The package still expects body-parser.","severity":"deprecated","affected_versions":">=4.16.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Remove 'new': const webhookHandler = GithubWebHook({ secret: '...' });","cause":"Using 'new' keyword on the factory function.","error":"TypeError: GithubWebHook is not a constructor"},{"fix":"Provide a secret matching the GitHub webhook secret, or disable signature verification by not setting a secret (not recommended).","cause":"Request has a signature but no secret was provided in options.","error":"Error: secret is required to verify signature"},{"fix":"Run 'npm install body-parser' and ensure it is required before the middleware.","cause":"body-parser not installed.","error":"Cannot find module 'body-parser'"},{"fix":"Use function(repo, data) for specific events, or function(event, repo, data) for '*' only.","cause":"Using incorrect callback signature for specific events.","error":"webhookHandler.on('push', function(event, repo, data) {...}) but event is undefined"},{"fix":"Add app.use(bodyParser.json()) before app.use(webhookHandler).","cause":"body-parser not applied before the middleware, leaving req.body as undefined.","error":"SyntaxError: Unexpected token u in JSON at position 0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}