Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Build a Live Activity Bus with Elysia SSE and Node.js EventEmitter

A practical single-process pattern for publishing Node.js activity events to authorized browser connections with Elysia SSE—and the cleanup and delivery limits to plan for.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A simple live activity feed can connect application code to browser tabs through four steps: publish a named event, dispatch it through a shared Node.js EventEmitter, stream it to each authorized browser connection with Elysia’s Server-Sent Events (SSE) support, and handle it with the browser’s EventSource API. This is a useful single-process starting point—not a durable queue or a cross-process broadcast system.

How the activity event travels to the browser

  1. Application code publishes. A handler or service emits a named event such as activity, with a payload that matches what its intended recipients may see.
  2. The shared emitter dispatches. A single EventEmitter instance, created at application composition level, calls the listeners registered for that event. Node.js documents that those callbacks run synchronously in registration order, and their return values are ignored. Keep synchronous work brief; an async listener does not cause emit() to wait for its promise. See the Node.js Events documentation.
  3. Each SSE handler streams an event. An authorized open connection has a listener that passes matching payloads into its stream. Elysia’s sse utility formats yielded values as text/event-stream; its SSE handler guide documents generator-based streaming.
  4. The browser receives and renders it. The page creates an EventSource, handles the event name it subscribed to, and updates its interface. The browser API is server-to-client; client actions need a separate HTTP request or another suitable transport. See MDN’s Using server-sent events.

Build the stream around authorization and cleanup

Authenticate and authorize the request before registering an emitter listener. A stream is a long-lived connection, so its listener must be removed when the response is cancelled or the client disconnects. Otherwise, disconnected clients can remain referenced by the emitter. Elysia documents that response cancellation stops the generator; the application must also release its own subscription when that happens.

As an Amazon Associate I earn from qualifying purchases.

The following is conceptual pseudocode, not verified drop-in code. Confirm generator and async-iteration details against the Elysia version in your project, and verify request-abort behavior with the runtime adapter you use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const bus = new EventEmitter()

app.get('/activity', function* ({ request }) {
  // Authenticate and authorize before subscribing.
  const queue = createPerConnectionQueue()
  const onActivity = (payload) => queue.push(payload)
  bus.on('activity', onActivity)

  try {
    while (!request.signal.aborted) {
      const payload = yield* queue.next()
      yield sse({ event: 'activity', data: payload })
    }
  } finally {
    bus.off('activity', onActivity)
  }
})

The queue stands in for the connection-specific handoff between synchronous emitter callbacks and the stream generator. Its implementation must define how it handles slow consumers and queued messages; the emitter itself does not supply stream backpressure or queue management. Set content, cache, and any required CORS or authentication-related headers before yielding the first chunk, as Elysia’s handler guidance requires headers to be set before streaming begins.

Choose SSE behavior with its delivery limits in mind

SSE is a one-way server-to-browser connection. MDN puts it plainly: “This is a one-way connection, so you can’t send events from a client to a server.” Use a normal authenticated POST or PUT endpoint for browser actions, or use a bidirectional protocol if the product requires continuous two-way communication.

An SSE message can contain data, a named event, an id, and a retry interval. EventSource can reconnect after a dropped connection, and comment lines can act as keep-alives during quiet periods. Reconnection alone does not guarantee that missed events will be delivered: replay requires retained history and application logic that interprets IDs or last-event state. A newly opened subscription likewise does not provide a historical snapshot, so request initial state separately or design explicit replay.

The in-memory emitter is scoped to the process that owns it. It does not, by itself, share events between multiple Node.js processes or preserve events for disconnected clients. If deployment requires cross-instance fan-out, consider an external pub/sub broker; if clients need replay, add a persistent event store and a defined retention/replay policy. These are separate capabilities, not properties of SSE or EventEmitter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for listener and runtime behavior

Node.js warns by default when more than 10 listeners are attached to one event. That warning is a possible leak diagnostic, not a hard client limit or capacity recommendation. Many simultaneous SSE connections can exceed the default when each adds a listener; first check that disconnect cleanup runs and measure active connections rather than reflexively disabling the warning. Node’s synchronous, ordered dispatch also means a slow listener can delay later listeners and the publisher’s call path.

Elysia documents Node.js support through the @elysia/node adapter. The official quick start uses new Elysia({ adapter: node() }) and .listen(...); Elysia is optimized for Bun, so Node is supported but is not its stated optimization target. Follow the current Elysia quick start for package and setup details rather than assuming a Bun setup transfers unchanged.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Architecture choices at a glance

Choice Direction Scope Reconnect delivery
SSE with one in-process EventEmitter Server to browser One process’s listeners Live events only unless the application adds retained history and replay
SSE with a shared broker and event store Server to browser Can coordinate multiple server instances, depending on broker design Replay depends on the event store and application logic
WebSocket-based design Bidirectional interaction model Depends on server and infrastructure design Retention and replay still require explicit application support

These options describe architectural differences, not a performance ranking. The right choice depends on whether the feed is live-only or replayable, whether instances must share events, and whether the browser needs to send messages over the same connection.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.