Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/ext/node/polyfills/events.ts>listenerCount

A modern runtime for JavaScript and TypeScript.
Latest
function listenerCount
Deprecated
Deprecated

Since v3.2.0 - Use listenerCount instead.

import { listenerCount } from "https://deno.land/x/deno@v2.0.4/ext/node/polyfills/events.ts";

A class method that returns the number of listeners for the given eventNameregistered on the given emitter.

const { EventEmitter, listenerCount } = require('events');
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2

Parameters

emitter: EventEmitter

The emitter to query

eventName: string | symbol

The event name

Returns

number