Stream Webhooks to Your Browser in Real-Time with SSE and Node.js

by Fahim Mahmud Chisti

Refreshing a database GUI or tailing logs just to see whether a webhook arrived gets old fast. This tutorial shows how to stream webhooks to your browser in real time with Server-Sent Events (SSE) and Node.js: an Express server receives each webhook and pushes it straight to a live dashboard page, with no WebSocket library and no build step.

Quick answer: Add a GET /events route that sets Content-Type: text/event-stream, keeps the response open and stores it in a list. When a webhook hits POST /webhook, write data: <json> followed by a blank line to every stored response. In the browser, new EventSource('/events') receives each one.

  1. Install Express and create server.js and index.html.
  2. Add the /events route with the three SSE headers, and remove clients when they disconnect.
  3. In /webhook, write each payload as data: …\n\n to every client.
  4. Open the page, which connects with EventSource and renders payloads with textContent.
  5. Send a test webhook with curl and watch it appear without a refresh.
In this guide
  1. Before You Start
  2. What You Will Build
  3. Why SSE Instead of WebSockets
  4. Step 1: Set Up the Project
  5. Step 2: Build the Express Server with an SSE Endpoint
  6. Step 3: Add the Webhook Receiver
  7. Step 4: Build the Dashboard Page
  8. Test It: Watch a Webhook Appear Live
  9. Clean Up Closed Connections
  10. If It Still Doesn’t Work
  11. Frequently Asked Questions
  12. Next Steps
  13. Official resources

Many developers reach for WebSockets for real-time updates, but here they are more than you need. If the server only has to push incoming webhook data to a browser tab, SSE is simpler and built into every modern browser.

Real-time webhook stream dashboard showing JSON payload and green connection badge next to a terminal

Before You Start

  • Node.js 18 or newer (a current LTS release is best).
  • A modern browser; all current browsers support EventSource.
  • Two terminal windows, one for the server and one for curl. The tutorial takes about 20 minutes.
  • Local use only, as written. The dashboard has no login and shows every header it receives, including signatures and tokens.

What You Will Build

  • server.js – an Express server with three routes: the dashboard page (/), the event stream (/events) and the webhook receiver (/webhook).
  • index.html – the dashboard, which connects to /events and shows each payload as a card.

Why SSE Instead of WebSockets

WebSockets suit collaborative whiteboards or chat apps, where client and server talk back and forth constantly. Webhooks are one-way: an external service calls your server, and your server tells the browser tab what happened.

SSE fits that because it runs over ordinary HTTP on one long-lived connection:

  • Built into the browser: there is no socket.io or client library to add. The browser’s EventSource API handles the connection.
  • Automatic reconnection: if the network drops, the browser reconnects on its own, so you do not write retry loops.
  • Firewall friendly: it is plain HTTP or HTTPS, so it passes through corporate firewalls that often block WebSocket connections.

Step 1: Set Up the Project

Run these commands in your terminal to create the project and install Express, the only dependency:

mkdir webhook-sse-streamer
cd webhook-sse-streamer
npm init -y
npm install express

The dashboard is served from the same origin as the event stream, so no CORS setup is needed. Create two empty files in the folder: server.js and index.html.

Step 2: Build the Express Server with an SSE Endpoint

An SSE response is an ordinary HTTP response that never ends, marked by special headers. Open server.js and start with the basic Express setup:

const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 4000;
app.use(express.json());
// Serve only the dashboard page, not the whole project folder
app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});
let clients = [];
app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

Now add the SSE endpoint. Paste it into server.js below the line let clients = [];. When the dashboard loads, it opens a connection to /events. The route sets the headers, stores the connection so it can broadcast later, and removes it when the tab closes:

app.get('/events', (req, res) => {
  res.setHeader('Content-Type', 'text/event-stream');
  res.setHeader('Cache-Control', 'no-cache');
  res.setHeader('Connection', 'keep-alive');
  res.write('data: {"status": "connected"}\n\n');
  const clientId = Date.now();
  const newClient = { id: clientId, res };
  clients.push(newClient);
  req.on('close', () => {
    console.log(`Client ${clientId} disconnected`);
    clients = clients.filter(client => client.id !== clientId);
  });
});

Note the two newline characters (\n\n) at the end of the res.write call. In the SSE format, a blank line marks the end of an event. Without it the browser keeps waiting, and your event listener never fires.

Step 3: Add the Webhook Receiver

Next you need an endpoint for third-party services to POST to. When a webhook arrives, the route packages it and streams it to every connected browser tab. Add this to server.js as well, below the /events route:

app.post('/webhook', (req, res) => {
  const webhookPayload = {
    timestamp: new Date().toISOString(),
    headers: req.headers,
    body: req.body,
    query: req.query
  };
  console.log('Received webhook:', JSON.stringify(webhookPayload, null, 2));
  clients.forEach(client => {
    client.res.write(`data: ${JSON.stringify(webhookPayload)}\n\n`);
  });
  res.status(200).json({ success: true, message: 'Webhook broadcasted' });
});

Each POST to /webhook is packaged with its headers, query parameters and JSON body. The loop then writes the data to every open connection in clients. If you want to reject malformed payloads before broadcasting them, validate webhook payloads with Zod in Express first.

This is a debugging tool with no authentication: anyone who can reach /events sees every header and body, including signatures and tokens. Keep it on localhost or put it behind a login.

Step 4: Build the Dashboard Page

The dashboard is one HTML file that uses the browser’s EventSource object, with no framework and no build step. Paste this into index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Real-Time Webhook Streamer</title>
<style>
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #121214;
  color: #e1e1e6;
  margin: 0;
  padding: 20px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #29292e;
  padding-bottom: 10px;
}
.status {
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 4px;
}
.connected {
  background-color: #04d361;
  color: #000;
}
.disconnected {
  background-color: #f74040;
  color: #fff;
}
#events-list {
  margin-top: 20px;
}
.event-card {
  background-color: #202024;
  border: 1px solid #29292e;
  border-radius: 6px;
  padding: 15px;
  margin-bottom: 15px;
}
pre {
  background-color: #121214;
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
  color: #50fa7b;
}
</style>
</head>
<body>
<header>
  <h1>Live Webhook Stream</h1>
  <span id="status-badge" class="status disconnected">Disconnected</span>
</header>
<div id="events-list"></div>
<script>
const statusBadge = document.getElementById('status-badge');
const eventsList = document.getElementById('events-list');
const eventSource = new EventSource('/events');
eventSource.onopen = () => {
  statusBadge.textContent = 'Connected';
  statusBadge.className = 'status connected';
};
eventSource.onerror = () => {
  statusBadge.textContent = 'Disconnected';
  statusBadge.className = 'status disconnected';
};
eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  if (data.status === 'connected') return;
  const card = document.createElement('div');
  card.className = 'event-card';
  const receivedAt = document.createElement('p');
  receivedAt.textContent = `Received at: ${data.timestamp}`;
  const payload = document.createElement('pre');
  // Use textContent, never innerHTML: webhook payloads are untrusted input
  payload.textContent = JSON.stringify(data.body, null, 2);
  card.append(receivedAt, payload);
  eventsList.insertBefore(card, eventsList.firstChild);
};
</script>
</body>
</html>

New payloads are added to the top of the list, so the latest webhook is always first. The script renders payloads with textContent, never innerHTML, because webhook data is untrusted input that could otherwise inject scripts into the page.

Test It: Watch a Webhook Appear Live

Start the server in your first terminal:

node server.js

You should see Server running on http://localhost:4000. Open http://localhost:4000 in your browser; the status badge turns green and says “Connected”.

Now open a second terminal and send a test webhook with curl:

curl -X POST http://localhost:4000/webhook -H "Content-Type: application/json" -d '{"event": "user.created", "user": {"id": 99, "email": "test@example.com"}}'

curl prints {"success":true,"message":"Webhook broadcasted"}. In the browser, a new card appears at the top with “Received at:” and the JSON payload, without a page refresh.

You can also watch the raw stream without a browser. Run curl -N http://localhost:4000/events in another terminal (-N turns off curl’s buffering). It prints data: {"status": "connected"} right away and one more data: line for each webhook you send.

To receive webhooks from real external services, test webhooks locally with Cloudflare Tunnels to expose the /webhook route. Keep the dashboard itself open on localhost, because Cloudflare’s quick tunnels do not carry SSE streams.

Clean Up Closed Connections

SSE connections drop all the time: users close tabs, reload pages or lose Wi-Fi. If you do not remove closed connections, the server keeps writing to them and its memory use grows.

That is what the req.on('close') handler in the /events route does. It is already in your code; this is the relevant part:

req.on('close', () => {
  clients = clients.filter(client => client.id !== clientId);
});

Without this filter, the clients array would keep references to dead response objects forever, and the Node.js process’s memory use would keep climbing until the server ran out.

If It Still Doesn’t Work

  • The badge stays “Disconnected”: the server is not running, or you opened the wrong port. The sample listens on 4000, not 3000.
  • The card shows undefined instead of the payload: the webhook request had no Content-Type: application/json header, so Express did not parse the body. Keep the -H flag in curl.
  • Events arrive late or in batches behind Nginx: the proxy is buffering the stream. Turn buffering off for /events with proxy_buffering off;, as in the guide to setting up an Nginx reverse proxy for Node.js. Compression middleware can cause the same delay.
  • Nothing arrives through a quick tunnel: quick tunnels do not support SSE. Open the dashboard on localhost.
  • A new tab hangs while several others are open: you have hit the browser’s HTTP/1.1 limit of 6 connections per site. Close some tabs or serve the app over HTTP/2.

Frequently Asked Questions

Does Server-Sent Events support POST requests?

No, the browser’s EventSource API only makes GET requests. If you need to send settings when the stream opens, put them in the query string of the /events URL. For anything more complex, make a normal POST request first and then open the stream.

How many SSE connections can a browser keep open?

Over HTTP/1.1, browsers allow about 6 open connections per site, and every SSE tab uses one. Open more tabs than that and new connections hang. Over HTTP/2, all streams share one connection and the limit is negotiated between browser and server, commonly 100 streams.

Can I send binary data over SSE?

No, SSE only carries text. Encode binary data as Base64 before sending, which makes it about a third larger. If your app mainly streams binary data, or the browser also needs to send data back, WebSockets are the better fit.

Next Steps

You now have a live webhook dashboard built on Express and native browser APIs. Point a provider’s test webhooks at it through a tunnel, and add a login before you run it anywhere other than localhost. Before trusting what you see, check that each request really came from the provider; see how to verify webhook signatures with HMAC in Node.js.

Official resources

all_in_one_marketing_tool