> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# node-event-listener-leak

> An event listener is registered inside a repeated or per-request context without matching cleanup.

## What it flags

`.on()`, `.addListener()`, or `.addEventListener()` is registered in a request handler, loop, or lifecycle hook without cleanup.

For example, calling `sharedSocket.on('close', handler)` on every iteration accumulates handlers on the same socket. The rule recognizes cases where each iteration creates its own Node.js socket. It also recognizes a registry's bulk registration method forwarding caller-supplied listeners to its own registration method with a corresponding removal API.

For a Node.js file read stream created inside a request handler, the rule recognizes a preceding request or response `close` callback or a request `aborted` callback that destroys the same stream. This requires a local stream that stays inside the handler.

For DOM elements, a render function can map its data to elements it creates with `document.createElement` and then give each element one listener in a single loop. The rule accepts that when the list is only iterated afterwards. Elements from a shared list, a list that is also modified, or a loop nested in another loop keep their finding. Streams returned by other factories are not assumed to be fresh.

A `this.on()`, `this.addListener()` or `this.addEventListener()` call inside a class method, constructor or accessor is not reported when the class has no `extends` clause and declares a method with a body of the same name (static or instance, matching the calling member). That call goes to the class's own registry, not an event emitter. The check is by method name only. For classes with an `extends` clause, the usual listener checks apply.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "node-event-listener-leak": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.