Skip to content

eventClasses

Prefer EventTarget over EventEmitter for cross-platform compatibility.

✅ This rule is included in the node logical preset.

While EventEmitter is only available in Node.js, EventTarget is available in browsers, Deno, and modern Node.js (v14.5+). Using EventTarget makes code more cross-platform friendly and can reduce bundle size in built packages.

import { EventEmitter } from "events";
class MyEmitter extends EventEmitter {}
const emitter = new EventEmitter();

This rule is not configurable.

If your code exclusively targets Node.js environments and you specifically need EventEmitter’s API features that are not available in EventTarget (for example, prependListener, once returning a cleanup function, or error events with special handling), you might choose not to enable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.