{"id":13725192,"url":"https://github.com/roccomuso/node-webhooks","last_synced_at":"2025-10-26T06:32:30.132Z","repository":{"id":37601933,"uuid":"51153264","full_name":"roccomuso/node-webhooks","owner":"roccomuso","description":":arrow_right_hook: Node.js module to create and trigger your own webHooks.","archived":false,"fork":false,"pushed_at":"2023-08-07T16:57:37.000Z","size":52,"stargazers_count":190,"open_issues_count":12,"forks_count":47,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-24T13:51:13.550Z","etag":null,"topics":["javascript","module","node","node-webhooks","nodejs","npm","trigger","webhooks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roccomuso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-05T15:04:35.000Z","updated_at":"2024-07-12T17:35:47.000Z","dependencies_parsed_at":"2024-06-18T14:06:48.054Z","dependency_job_id":"ba790215-6997-409b-a518-013b6b44d6d9","html_url":"https://github.com/roccomuso/node-webhooks","commit_stats":{"total_commits":68,"total_committers":7,"mean_commits":9.714285714285714,"dds":0.5441176470588236,"last_synced_commit":"baf14131778e177657471d298d627f9ca978d929"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roccomuso%2Fnode-webhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roccomuso%2Fnode-webhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roccomuso%2Fnode-webhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roccomuso%2Fnode-webhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roccomuso","download_url":"https://codeload.github.com/roccomuso/node-webhooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271530,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","module","node","node-webhooks","nodejs","npm","trigger","webhooks"],"created_at":"2024-08-03T01:02:15.433Z","updated_at":"2025-10-26T06:32:30.077Z","avatar_url":"https://github.com/roccomuso.png","language":"JavaScript","readme":"# node-webhooks [![Build Status](https://travis-ci.org/roccomuso/node-webhooks.svg?branch=master)](https://travis-ci.org/roccomuso/node-webhooks) [![NPM Version](https://img.shields.io/npm/v/node-webhooks.svg)](https://www.npmjs.com/package/node-webhooks) [![Coverage Status](https://coveralls.io/repos/github/roccomuso/node-webhooks/badge.svg?branch=master)](https://coveralls.io/github/roccomuso/node-webhooks?branch=master) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Dependency Status](https://david-dm.org/roccomuso/node-webhooks.png)](https://david-dm.org/roccomuso/node-webhooks) \u003cspan class=\"badge-patreon\"\u003e\u003ca href=\"https://patreon.com/roccomuso\" title=\"Donate to this project using Patreon\"\u003e\u003cimg src=\"https://img.shields.io/badge/patreon-donate-yellow.svg\" alt=\"Patreon donate button\" /\u003e\u003c/a\u003e\u003c/span\u003e\n\n## What WebHooks are used for\n\n\u003e Webhooks are \"user-defined HTTP callbacks\". They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URI configured for the webhook. Users can configure them to cause events on one site to invoke behaviour on another. The action taken may be anything. Common uses are to trigger builds with continuous integration systems or to notify bug tracking systems. Since they use HTTP, they can be integrated into web services without adding new infrastructure.\n\n## Install\n\n    npm install node-webhooks --save\n\nSupporting Node.js 0.12 or above.\n\n## How it works\n\nWhen a webHook is triggered it will send an HTTPS POST request to the attached URLs, containing a JSON-serialized Update (the one specified when you call the **trigger** method).\n\n## Debug\n\nThis module makes use of the popular [debug](https://github.com/visionmedia/debug) package. Use the env variable to enable debug: \u003ccode\u003eDEBUG=node-webhooks\u003c/code\u003e.\nTo launch the example and enable debug: \u003ccode\u003eDEBUG=node-webhooks node example.js\u003c/code\u003e\n\n## Usage\n\n```javascript\n\n// Initialize WebHooks module.\nvar WebHooks = require('node-webhooks')\n\n// Initialize webhooks module from on-disk database\nvar webHooks = new WebHooks({\n    db: './webHooksDB.json', // json file that store webhook URLs\n    httpSuccessCodes: [200, 201, 202, 203, 204], //optional success http status codes\n})\n\n// Alternatively, initialize webhooks module with object; changes will only be\n// made in-memory\nwebHooks = new WebHooks({\n    db: {\"addPost\": [\"http://localhost:9100/posts\"]}, // just an example\n})\n\n// sync instantation - add a new webhook called 'shortname1'\nwebHooks.add('shortname1', 'http://127.0.0.1:9000/prova/other_url').then(function(){\n\t// done\n}).catch(function(err){\n\tconsole.log(err)\n})\n\n// add another webHook\nwebHooks.add('shortname2', 'http://127.0.0.1:9000/prova2/').then(function(){\n\t// done\n}).catch(function(err){\n\tconsole.log(err)\n});\n\n// remove a single url attached to the given shortname\n// webHooks.remove('shortname3', 'http://127.0.0.1:9000/query/').catch(function(err){console.error(err);})\n\n// if no url is provided, remove all the urls attached to the given shortname\n// webHooks.remove('shortname3').catch(function(err){console.error(err);})\n\n// trigger a specific webHook\nwebHooks.trigger('shortname1', {data: 123})\nwebHooks.trigger('shortname2', {data: 123456}, {header: 'header'}) // payload will be sent as POST request with JSON body (Content-Type: application/json) and custom header\n\n```\n\n## Available events\n\nWe're using an event emitter library to expose request information on webHook trigger.\n\n```javascript\nvar webHooks = new WebHooks({\n    db: WEBHOOKS_DB,\n    DEBUG: true\n})\n\nvar emitter = webHooks.getEmitter()\n\nemitter.on('*.success', function (shortname, statusCode, body) {\n    console.log('Success on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body)\n})\n\nemitter.on('*.failure', function (shortname, statusCode, body) {\n    console.error('Error on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body)\n})\n```\n\nThis makes possible checking if a webHook trigger was successful or not getting request information such as status code or response body.\n\nThe format for the events is built as `eventName.result`. The choosen library `eventemitter2` provides a lot of freedom for listening events. For example:\n\n- `eventName.success`\n- `eventName.failure`\n- `eventName.*`\n- `*.success`\n- `*.*`\n\n\n## API examples\n\nwebHooks are useful whenever you need to make sure that an external service get updates from your app.\nYou can easily develop in your APP this kind of webHooks entry-points.\n\n- \u003ccode\u003eGET /api/webhook/get\u003c/code\u003e\nReturn the whole webHook DB file.\n\n- \u003ccode\u003eGET /api/webhook/get/[WebHookShortname]\u003c/code\u003e\nReturn the selected WebHook.\n\n- \u003ccode\u003ePOST /api/webhook/add/[WebHookShortname]\u003c/code\u003e\nAdd a new URL for the selected webHook. Requires JSON params:\n\n- \u003ccode\u003eGET /api/webhook/delete/[WebHookShortname]\u003c/code\u003e\nRemove all the urls attached to the selected webHook.\n\n- \u003ccode\u003ePOST /api/webhook/delete/[WebHookShortname]\u003c/code\u003e\nRemove only one single url attached to the selected webHook.\nA json body with the url parameter is required: { \"url\": \"http://...\" }\n\n- \u003ccode\u003ePOST /api/webhook/trigger/[WebHookShortname]\u003c/code\u003e\nTrigger a webHook. It requires a JSON body that will be turned over to the webHook URLs. You can also provide custom headers.\n\n\n\n### Author\n\nRocco Musolino - [@roccomuso](https://twitter.com/roccomuso)\n","funding_links":["https://patreon.com/roccomuso"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froccomuso%2Fnode-webhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froccomuso%2Fnode-webhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froccomuso%2Fnode-webhooks/lists"}