# @twilio/replay-event-emitter

> An extension to Node's EventEmitter that supports event replay.

Latest version **1.0.0** (published 2026-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @twilio/replay-event-emitter
pnpm add @twilio/replay-event-emitter
yarn add @twilio/replay-event-emitter
bun add @twilio/replay-event-emitter
```

## Health

**Score 50/100 (C)** — status: active.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-03-18 |
| First published | 2021-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 2 |
| Unpacked size | 140.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Lysenko |
| Maintainers | twilio-messaging |

## Links

- npm: https://www.npmjs.com/package/@twilio/replay-event-emitter
- npm.io page: https://npm.io/package/@twilio/replay-event-emitter

## Dependencies (2)

- [core-js](https://npm.io/package/core-js.md) ^3.17.3
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.17.0

## Recent versions

- 1.0.0 (latest) — 2026-03-18
- 1.0.0-rc.11 (alpha) — 2026-02-27
- 0.3.0-canary.9 (canary) — 2022-04-27
- 0.1.0-main.29 (main) — 2021-08-24
- 0.4.0 — 2026-02-19
- 0.4.0-rc.2 — 2026-02-19
- 0.4.0-rc.0 — 2026-02-19
- 0.3.14-rc.1 — 2026-02-19
- 0.3.14-rc.0 — 2026-02-17
- 0.3.13 — 2025-11-18
- 0.3.13-rc.0 — 2025-11-18
- 0.3.12 — 2025-09-29
- 0.3.12-rc.3 — 2025-09-16
- 0.3.12-rc.0 — 2025-08-01
- 0.3.11 — 2025-07-29
- … 80 more at https://npm.io/package/@twilio/replay-event-emitter/versions

## README

# EventReplayEmitter

An extension to Node's EventEmitter that supports event replay. In other words,
if a listener is added using either `addListenerWithReplay` or `onWithReplay`,
then it will instantly trigger the listener with previous event data (if no data
was previously emitted, then the listener will not get triggered on 
registration).

## Usage Examples

In order to get event replay on listener registration, simply utilize the
`addListenerWithReplay` method like so:

```js
import { ReplayEventEmitter } from "replay-event-emitter";

// Instantiate the event emitter
const eventEmitter = new ReplayEventEmitter();

// Emit an event before adding a listener
eventEmitter.emit("exampleEvent", "someData");

// Subscribe using addListenerWithReplay
eventEmitter.addListenerWithReplay("exampleEvent", (data) => {
  // This handler will get triggered despite the data emission happening BEFORE
  // the event registration.
  console.log(data);
});
```

You could also use the shorthand method `onWithRepeat`, like so:

```js
eventEmitter.onWithReplay("exampleEvent", (data) => {
  console.log(data);
});
```

All the original functionality of the EventEmitter is still intact:

```js
import { ReplayEventEmitter } from "replay-event-emitter";

const eventEmitter = new ReplayEventEmitter();

eventEmitter.emit("exampleEvent", "someData");

eventEmitter.addListener("exampleEvent", (data) => {
  // This handler will NOT get triggered, as this is not a replay method and the
  // data emission happened BEFORE the event registration.
  console.log(data);
});
```

---
_Source: https://npm.io/package/@twilio/replay-event-emitter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
