Building a Webhook Listener with Node.js (Step-by-Step Guide)

Webhooks power modern integrations — whether it’s receiving payment notifications from Stripe, alerts from GitHub, or messages from Slack. Instead of constantly polling an API, you let the service push events to your app in real time.

In this post, we…


This content originally appeared on DEV Community and was authored by lucas-brdt268

Webhooks power modern integrations — whether it’s receiving payment notifications from Stripe, alerts from GitHub, or messages from Slack. Instead of constantly polling an API, you let the service push events to your app in real time.

In this post, we’ll build a simple webhook listener using Node.js + Express. By the end, you’ll know how to:

  • Understand what a webhook is
  • Set up a webhook endpoint in Node.js
  • Parse and log incoming events
  • Test your webhook locally with Ngrok

🧩 What is a Webhook?

A webhook is just an HTTP callback.

  • A service sends an HTTP request (usually POST) to your app when something happens.
  • Your app receives that request, processes it, and responds.

Example:

  • GitHub → sends a POST /webhook with info about a new pull request
  • Your app → logs the event or triggers another process

⚡ Step 1. Setup Project

mkdir node-webhook-listener
cd node-webhook-listener
npm init -y
npm install express body-parser

⚡ Step 2. Create Express Server

Create a file: index.js

const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const PORT = process.env.PORT || 3000;

// Middleware to parse JSON
app.use(bodyParser.json());

// Webhook endpoint
app.post('/webhook', (req, res) => {
  console.log('📩 Webhook received:', req.body);

  // Always reply with 200 OK so the sender knows you got it
  res.status(200).send('Webhook received');
});

app.listen(PORT, () => {
  console.log(`🚀 Server is running on http://localhost:${PORT}`);
});

Run it:

node index.js

⚡ Step 3. Test Locally with Ngrok

External services can’t reach localhost, so we need to expose it with Ngrok.

npx ngrok http 3000

Ngrok will give you a public URL, like:

https://abc123.ngrok.io

Now, if you send a webhook to:

https://abc123.ngrok.io/webhook

It will forward it to your local server. 🎉

⚡ Step 4. Send a Test Request

You can simulate an external webhook using curl:

curl -X POST https://abc123.ngrok.io/webhook \
  -H "Content-Type: application/json" \
  -d '{"event":"order.created","data":{"id":123,"amount":500}}'

Check your terminal — you should see:

📩 Webhook received: { event: 'order.created', data: { id: 123, amount: 500 } }

🛡️ (Optional) Step 5. Secure Your Webhook

Most services sign webhook payloads with a secret. You should:

  • Verify the signature (HMAC)
  • Only accept requests from trusted sources
  • Avoid logging sensitive data

(We’ll dive deeper into webhook security in another post 👀)

🎯 Wrap Up

We just built a basic webhook listener in Node.js:

✅ Express server with /webhook endpoint
✅ Logging incoming events
✅ Local testing with Ngrok
✅ Ready to integrate with APIs like Stripe, GitHub, or Slack

Next steps:

  • Add signature verification
  • Connect the webhook events to your app’s logic
  • Deploy to a cloud service

👉 What services are you planning to integrate with webhooks? Let me know in the comments!


This content originally appeared on DEV Community and was authored by lucas-brdt268


Print Share Comment Cite Upload Translate Updates
APA

lucas-brdt268 | Sciencx (2025-09-28T15:18:55+00:00) Building a Webhook Listener with Node.js (Step-by-Step Guide). Retrieved from https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/

MLA
" » Building a Webhook Listener with Node.js (Step-by-Step Guide)." lucas-brdt268 | Sciencx - Sunday September 28, 2025, https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/
HARVARD
lucas-brdt268 | Sciencx Sunday September 28, 2025 » Building a Webhook Listener with Node.js (Step-by-Step Guide)., viewed ,<https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/>
VANCOUVER
lucas-brdt268 | Sciencx - » Building a Webhook Listener with Node.js (Step-by-Step Guide). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/
CHICAGO
" » Building a Webhook Listener with Node.js (Step-by-Step Guide)." lucas-brdt268 | Sciencx - Accessed . https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/
IEEE
" » Building a Webhook Listener with Node.js (Step-by-Step Guide)." lucas-brdt268 | Sciencx [Online]. Available: https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/. [Accessed: ]
rf:citation
» Building a Webhook Listener with Node.js (Step-by-Step Guide) | lucas-brdt268 | Sciencx | https://www.scien.cx/2025/09/28/building-a-webhook-listener-with-node-js-step-by-step-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.