This is a lightweight
npm-package to manage
What WebHooks are used for
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.
npm i -s webhook-manager
How it works
To receive webhooks, we basically just need to setup a webserver and start listening for incomming
POST-requests. This is, what this plugin does.
We setup an
express-server on a specific
port and then start listening for all incomming
POST-requests. The requests get filtered, if a
webhook is listening for it - if yes, then an event to this registered
webhook gets emitted.
// Import the packageconst WebhookManager = ;// Create a new instance of the Webhook-Manager with a specific port to listen onconst manager = 4848;// Just a listener for the "ready"-event// It get's fired, when the manager is setup properlymanager;// Register a new Webhook-Listener// It listens for everything, that goes directly to '// The callback gets fired, when a webhook is received// 'data' is the request, received by the listenermanager;