# node:events

> How Elide supports Node's `events` module: EventEmitter, once() and on() with an AbortSignal, captureRejections, and the EventEmitterAsyncResource and EventSource gaps.

`node:events` provides [Node's `EventEmitter`](https://nodejs.org/api/events.html), `once()` and `on()` with an
`AbortSignal`, `once()` on an `EventTarget`, `captureRejections` and `EventEmitterAsyncResource`.

## Example

```js
// events.mjs
import { EventEmitter, once } from "node:events";

const jobs = new EventEmitter();
jobs.on("done", (id) => console.log(`job ${id} done`));
jobs.emit("done", 1);

setTimeout(() => jobs.emit("idle", 3), 10);
const [pending] = await once(jobs, "idle");
console.log("idle with", pending, "listeners:", jobs.listenerCount("done"));
```

`elide run events.mjs` prints:

```text
job 1 done
idle with 3 listeners: 1
```

## Differences from Node

- `EventEmitterAsyncResource#asyncResource.eventEmitter` does not return the emitter.
- There is no `EventSource` global.

<!-- api-reference:start 05378e039bdb -->
## Reference

**Status:** Full · 34 of 38 suite tests pass (89.5%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `EventEmitter` | class | Full | `addListener()`, `on()`, `once()`, `prependListener()`, `prependOnceListener()`, `removeListener()`, `off()`, `removeAllListeners()`, `emit()`, `listenerCount()`, `listeners()`, `rawListeners()`, `eventNames()`, `setMaxListeners()`, `getMaxListeners()`, `EventEmitter.defaultMaxListeners`, `EventEmitter.once()`, `EventEmitter.listenerCount()` |

**Tests:** [node-api `node:events`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 34 pass, 3 fail, 1 error, 6 skipped. Failing: `test-event-capture-rejections.js`, `test-eventemitter-asyncresource.js`, `test-events-once.js`, `test-eventsource.js`.
<!-- api-reference:end -->
