{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"events","path":"/events","type":"module","module":"events","title":"Events","introducedIn":"v0.10.0","sourceLink":{"path":"lib/events.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/events.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Much of the Node.js core API is built around an idiomatic asynchronous\nevent-driven architecture in which certain kinds of objects (called \"emitters\")\nemit named events that cause `Function` objects (\"listeners\") to be called.\n\nFor instance: a [`net.Server`](net.html#class-netserver) object emits an event each time a peer\nconnects to it; a [`fs.ReadStream`](fs.html#class-fsreadstream) emits an event when the file is opened;\na [stream](stream.html) emits an event whenever data is available to be read.\n\nAll objects that emit events are instances of the `EventEmitter` class. These\nobjects expose an `eventEmitter.on()` function that allows one or more\nfunctions to be attached to named events emitted by the object. Typically,\nevent names are camel-cased strings but any valid JavaScript property key\ncan be used.\n\nWhen the `EventEmitter` object emits an event, all of the functions attached\nto that specific event are called *synchronously*. Any values returned by the\ncalled listeners are *ignored* and discarded.\n\nThe following example shows a simple `EventEmitter` instance with a single\nlistener. The `eventEmitter.on()` method is used to register listeners, while\nthe `eventEmitter.emit()` method is used to trigger the event.\n\n```mjs\nimport { EventEmitter } from 'node:events';\n\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', () => {\n  console.log('an event occurred!');\n});\nmyEmitter.emit('event');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\n\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', () => {\n  console.log('an event occurred!');\n});\nmyEmitter.emit('event');\n```","summary":"Much of the Node.js core API is built around an idiomatic asynchronous event-driven architecture in which certain kinds of objects (called \"emitters\") emit named events that cause `Function` objects (\"listeners\") to be called.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\n\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', () => {\n  console.log('an event occurred!');\n});\nmyEmitter.emit('event');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\n\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', () => {\n  console.log('an event occurred!');\n});\nmyEmitter.emit('event');"}],"children":[{"kind":"section","id":"passing-arguments-and-this-to-listeners","name":"Passing arguments and this to listeners","title":"Passing arguments and `this` to listeners","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `eventEmitter.emit()` method allows an arbitrary set of arguments to be\npassed to the listener functions. Keep in mind that when\nan ordinary listener function is called, the standard `this` keyword\nis intentionally set to reference the `EventEmitter` instance to which the\nlistener is attached.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', function(a, b) {\n  console.log(a, b, this, this === myEmitter);\n  // Prints:\n  //   a b MyEmitter {\n  //     _events: [Object: null prototype] { event: [Function (anonymous)] },\n  //     _eventsCount: 1,\n  //     _maxListeners: undefined,\n  //     Symbol(shapeMode): false,\n  //     Symbol(kCapture): false\n  //   } true\n});\nmyEmitter.emit('event', 'a', 'b');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', function(a, b) {\n  console.log(a, b, this, this === myEmitter);\n  // Prints:\n  //   a b MyEmitter {\n  //     _events: [Object: null prototype] { event: [Function (anonymous)] },\n  //     _eventsCount: 1,\n  //     _maxListeners: undefined,\n  //     Symbol(shapeMode): false,\n  //     Symbol(kCapture): false\n  //   } true\n});\nmyEmitter.emit('event', 'a', 'b');\n```\n\nIt is possible to use ES6 Arrow Functions as listeners, however, when doing so,\nthe `this` keyword will no longer reference the `EventEmitter` instance:\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  console.log(a, b, this);\n  // Prints: a b undefined\n});\nmyEmitter.emit('event', 'a', 'b');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  console.log(a, b, this);\n  // Prints: a b {}\n});\nmyEmitter.emit('event', 'a', 'b');\n```","summary":"The `eventEmitter.emit()` method allows an arbitrary set of arguments to be passed to the listener functions. Keep in mind that when an ordinary listener function is called, the standard `this` keyword is intentionally set to reference the `EventEmitter` instance to which the listener is attached.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', function(a, b) {\n  console.log(a, b, this, this === myEmitter);\n  // Prints:\n  //   a b MyEmitter {\n  //     _events: [Object: null prototype] { event: [Function (anonymous)] },\n  //     _eventsCount: 1,\n  //     _maxListeners: undefined,\n  //     Symbol(shapeMode): false,\n  //     Symbol(kCapture): false\n  //   } true\n});\nmyEmitter.emit('event', 'a', 'b');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', function(a, b) {\n  console.log(a, b, this, this === myEmitter);\n  // Prints:\n  //   a b MyEmitter {\n  //     _events: [Object: null prototype] { event: [Function (anonymous)] },\n  //     _eventsCount: 1,\n  //     _maxListeners: undefined,\n  //     Symbol(shapeMode): false,\n  //     Symbol(kCapture): false\n  //   } true\n});\nmyEmitter.emit('event', 'a', 'b');"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  console.log(a, b, this);\n  // Prints: a b undefined\n});\nmyEmitter.emit('event', 'a', 'b');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  console.log(a, b, this);\n  // Prints: a b {}\n});\nmyEmitter.emit('event', 'a', 'b');"}],"children":[]},{"kind":"section","id":"asynchronous-vs-synchronous","name":"Asynchronous vs. synchronous","title":"Asynchronous vs. synchronous","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `EventEmitter` calls all listeners synchronously in the order in which\nthey were registered. This ensures the proper sequencing of\nevents and helps avoid race conditions and logic errors. When appropriate,\nlistener functions can switch to an asynchronous mode of operation using\nthe `setImmediate()` or `process.nextTick()` methods:\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  setImmediate(() => {\n    console.log('this happens asynchronously');\n  });\n});\nmyEmitter.emit('event', 'a', 'b');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  setImmediate(() => {\n    console.log('this happens asynchronously');\n  });\n});\nmyEmitter.emit('event', 'a', 'b');\n```","summary":"The `EventEmitter` calls all listeners synchronously in the order in which they were registered. This ensures the proper sequencing of events and helps avoid race conditions and logic errors. When appropriate, listener functions can switch to an asynchronous mode of operation using the `setImmediate()` or `process.nextTick()` methods:","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  setImmediate(() => {\n    console.log('this happens asynchronously');\n  });\n});\nmyEmitter.emit('event', 'a', 'b');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  setImmediate(() => {\n    console.log('this happens asynchronously');\n  });\n});\nmyEmitter.emit('event', 'a', 'b');"}],"children":[]},{"kind":"section","id":"handling-events-only-once","name":"Handling events only once","title":"Handling events only once","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When a listener is registered using the `eventEmitter.on()` method, that\nlistener is invoked *every time* the named event is emitted.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.on('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Prints: 2\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.on('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Prints: 2\n```\n\nUsing the `eventEmitter.once()` method, it is possible to register a listener\nthat is called at most once for a particular event. Once the event is emitted,\nthe listener is unregistered and *then* called.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.once('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Ignored\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.once('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Ignored\n```","summary":"When a listener is registered using the `eventEmitter.on()` method, that listener is invoked _every time_ the named event is emitted.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.on('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Prints: 2"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.on('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Prints: 2"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.once('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Ignored"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nlet m = 0;\nmyEmitter.once('event', () => {\n  console.log(++m);\n});\nmyEmitter.emit('event');\n// Prints: 1\nmyEmitter.emit('event');\n// Ignored"}],"children":[]},{"kind":"section","id":"error-events","name":"Error events","title":"Error events","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When an error occurs within an `EventEmitter` instance, the typical action is\nfor an `'error'` event to be emitted. These are treated as special cases\nwithin Node.js.\n\nIf an `EventEmitter` does *not* have at least one listener registered for the\n`'error'` event, and an `'error'` event is emitted, the error is thrown, a\nstack trace is printed, and the Node.js process exits.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.emit('error', new Error('whoops!'));\n// Throws and crashes Node.js\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.emit('error', new Error('whoops!'));\n// Throws and crashes Node.js\n```\n\nTo guard against crashing the Node.js process the [`domain`](domain.html) module can be\nused. (Note, however, that the `node:domain` module is deprecated.)\n\nAs a best practice, listeners should always be added for the `'error'` events.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('error', (err) => {\n  console.error('whoops! there was an error');\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Prints: whoops! there was an error\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('error', (err) => {\n  console.error('whoops! there was an error');\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Prints: whoops! there was an error\n```\n\nIt is possible to monitor `'error'` events without consuming the emitted error\nby installing a listener using the symbol `events.errorMonitor`.\n\n```mjs\nimport { EventEmitter, errorMonitor } from 'node:events';\n\nconst myEmitter = new EventEmitter();\nmyEmitter.on(errorMonitor, (err) => {\n  MyMonitoringTool.log(err);\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Still throws and crashes Node.js\n```\n\n```cjs\nconst { EventEmitter, errorMonitor } = require('node:events');\n\nconst myEmitter = new EventEmitter();\nmyEmitter.on(errorMonitor, (err) => {\n  MyMonitoringTool.log(err);\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Still throws and crashes Node.js\n```","summary":"When an error occurs within an `EventEmitter` instance, the typical action is for an `'error'` event to be emitted. These are treated as special cases within Node.js.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.emit('error', new Error('whoops!'));\n// Throws and crashes Node.js"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.emit('error', new Error('whoops!'));\n// Throws and crashes Node.js"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('error', (err) => {\n  console.error('whoops! there was an error');\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Prints: whoops! there was an error"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\nmyEmitter.on('error', (err) => {\n  console.error('whoops! there was an error');\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Prints: whoops! there was an error"},{"language":"mjs","displayName":null,"code":"import { EventEmitter, errorMonitor } from 'node:events';\n\nconst myEmitter = new EventEmitter();\nmyEmitter.on(errorMonitor, (err) => {\n  MyMonitoringTool.log(err);\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Still throws and crashes Node.js"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, errorMonitor } = require('node:events');\n\nconst myEmitter = new EventEmitter();\nmyEmitter.on(errorMonitor, (err) => {\n  MyMonitoringTool.log(err);\n});\nmyEmitter.emit('error', new Error('whoops!'));\n// Still throws and crashes Node.js"}],"children":[]},{"kind":"section","id":"capture-rejections-of-promises","name":"Capture rejections of promises","title":"Capture rejections of promises","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Using `async` functions with event handlers is problematic, because it\ncan lead to an unhandled rejection in case of a thrown exception:\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst ee = new EventEmitter();\nee.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst ee = new EventEmitter();\nee.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n```\n\nThe `captureRejections` option in the `EventEmitter` constructor or the global\nsetting change this behavior, installing a `.then(undefined, handler)`\nhandler on the `Promise`. This handler routes the exception\nasynchronously to the [`Symbol.for('nodejs.rejection')`](#emittersymbolfornodejsrejectionerr-eventname-args) method\nif there is one, or to [`'error'`](#error-events) event handler if there is none.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst ee1 = new EventEmitter({ captureRejections: true });\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n\nconst ee2 = new EventEmitter({ captureRejections: true });\nee2.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee2[Symbol.for('nodejs.rejection')] = console.log;\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst ee1 = new EventEmitter({ captureRejections: true });\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n\nconst ee2 = new EventEmitter({ captureRejections: true });\nee2.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee2[Symbol.for('nodejs.rejection')] = console.log;\n```\n\nSetting `events.captureRejections = true` will change the default for all\nnew instances of `EventEmitter`.\n\n```mjs\nimport { EventEmitter } from 'node:events';\n\nEventEmitter.captureRejections = true;\nconst ee1 = new EventEmitter();\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n```\n\n```cjs\nconst events = require('node:events');\nevents.captureRejections = true;\nconst ee1 = new events.EventEmitter();\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n```\n\nThe `'error'` events that are generated by the `captureRejections` behavior\ndo not have a catch handler to avoid infinite error loops: the\nrecommendation is to **not use `async` functions as `'error'` event handlers**.","summary":"Using `async` functions with event handlers is problematic, because it can lead to an unhandled rejection in case of a thrown exception:","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst ee = new EventEmitter();\nee.on('something', async (value) => {\n  throw new Error('kaboom');\n});"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst ee = new EventEmitter();\nee.on('something', async (value) => {\n  throw new Error('kaboom');\n});"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst ee1 = new EventEmitter({ captureRejections: true });\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n\nconst ee2 = new EventEmitter({ captureRejections: true });\nee2.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee2[Symbol.for('nodejs.rejection')] = console.log;"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst ee1 = new EventEmitter({ captureRejections: true });\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);\n\nconst ee2 = new EventEmitter({ captureRejections: true });\nee2.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee2[Symbol.for('nodejs.rejection')] = console.log;"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\n\nEventEmitter.captureRejections = true;\nconst ee1 = new EventEmitter();\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);"},{"language":"cjs","displayName":null,"code":"const events = require('node:events');\nevents.captureRejections = true;\nconst ee1 = new events.EventEmitter();\nee1.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n\nee1.on('error', console.log);"}],"children":[]},{"kind":"class","id":"class-eventemitter","name":"EventEmitter","title":"Class: `EventEmitter`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v13.4.0","v12.16.0"],"prUrl":"https://github.com/nodejs/node/pull/27867","commit":null,"description":"Added captureRejections option."}],"extends":null,"description":"The `EventEmitter` class is defined and exposed by the `node:events` module:\n\n```mjs\nimport { EventEmitter } from 'node:events';\n```\n\n```cjs\nconst EventEmitter = require('node:events');\n```\n\nAll `EventEmitter`s emit the event `'newListener'` when new listeners are\nadded and `'removeListener'` when existing listeners are removed.\n\nIt supports the following option:\n\n* `captureRejections` {boolean} It enables\n  [automatic capturing of promise rejection](#capture-rejections-of-promises).\n  **Default:** `false`.","summary":"The `EventEmitter` class is defined and exposed by the `node:events` module:","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');"}],"children":[{"kind":"event","id":"event-newlistener","name":"newListener","title":"Event: `'newListener'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event being listened for","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The event handler function","default":null,"optional":false,"rest":false,"properties":[]}],"description":"The `EventEmitter` instance will emit its own `'newListener'` event *before*\na listener is added to its internal array of listeners.\n\nListeners registered for the `'newListener'` event are passed the event\nname and a reference to the listener being added.\n\nThe fact that the event is triggered before adding the listener has a subtle\nbut important side effect: any *additional* listeners registered to the same\n`name` *within* the `'newListener'` callback are inserted *before* the\nlistener that is in the process of being added.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\n// Only do this once so we don't loop forever\nmyEmitter.once('newListener', (event, listener) => {\n  if (event === 'event') {\n    // Insert a new listener in front\n    myEmitter.on('event', () => {\n      console.log('B');\n    });\n  }\n});\nmyEmitter.on('event', () => {\n  console.log('A');\n});\nmyEmitter.emit('event');\n// Prints:\n//   B\n//   A\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\n// Only do this once so we don't loop forever\nmyEmitter.once('newListener', (event, listener) => {\n  if (event === 'event') {\n    // Insert a new listener in front\n    myEmitter.on('event', () => {\n      console.log('B');\n    });\n  }\n});\nmyEmitter.on('event', () => {\n  console.log('A');\n});\nmyEmitter.emit('event');\n// Prints:\n//   B\n//   A\n```","summary":"The `EventEmitter` instance will emit its own `'newListener'` event _before_ a listener is added to its internal array of listeners.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\n// Only do this once so we don't loop forever\nmyEmitter.once('newListener', (event, listener) => {\n  if (event === 'event') {\n    // Insert a new listener in front\n    myEmitter.on('event', () => {\n      console.log('B');\n    });\n  }\n});\nmyEmitter.on('event', () => {\n  console.log('A');\n});\nmyEmitter.emit('event');\n// Prints:\n//   B\n//   A"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\n\nconst myEmitter = new MyEmitter();\n// Only do this once so we don't loop forever\nmyEmitter.once('newListener', (event, listener) => {\n  if (event === 'event') {\n    // Insert a new listener in front\n    myEmitter.on('event', () => {\n      console.log('B');\n    });\n  }\n});\nmyEmitter.on('event', () => {\n  console.log('A');\n});\nmyEmitter.emit('event');\n// Prints:\n//   B\n//   A"}],"children":[]},{"kind":"event","id":"event-removelistener","name":"removeListener","title":"Event: `'removeListener'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v6.1.0","v4.7.0"],"prUrl":"https://github.com/nodejs/node/pull/6394","commit":null,"description":"For listeners attached using `.once()`, the `listener` argument now yields the original listener function."}],"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The event name","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The event handler function","default":null,"optional":false,"rest":false,"properties":[]}],"description":"The `'removeListener'` event is emitted *after* the `listener` is removed.","summary":"The `'removeListener'` event is emitted _after_ the `listener` is removed.","examples":[],"children":[]},{"kind":"method","id":"emitteraddlistenereventname-listener","name":"addListener","title":"`emitter.addListener(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Alias for `emitter.on(eventName, listener)`.","summary":"Alias for `emitter.on(eventName, listener)`.","examples":[],"children":[]},{"kind":"method","id":"emitteremiteventname-args","name":"emit","title":"`emitter.emit(eventName[, ...args])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"args","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":true,"rest":true,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Synchronously calls each of the listeners registered for the event named\n`eventName`, in the order they were registered, passing the supplied arguments\nto each.\n\nReturns `true` if the event had listeners, `false` otherwise.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst myEmitter = new EventEmitter();\n\n// First listener\nmyEmitter.on('event', function firstListener() {\n  console.log('Helloooo! first listener');\n});\n// Second listener\nmyEmitter.on('event', function secondListener(arg1, arg2) {\n  console.log(`event with parameters ${arg1}, ${arg2} in second listener`);\n});\n// Third listener\nmyEmitter.on('event', function thirdListener(...args) {\n  const parameters = args.join(', ');\n  console.log(`event with parameters ${parameters} in third listener`);\n});\n\nconsole.log(myEmitter.listeners('event'));\n\nmyEmitter.emit('event', 1, 2, 3, 4, 5);\n\n// Prints:\n// [\n//   [Function: firstListener],\n//   [Function: secondListener],\n//   [Function: thirdListener]\n// ]\n// Helloooo! first listener\n// event with parameters 1, 2 in second listener\n// event with parameters 1, 2, 3, 4, 5 in third listener\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst myEmitter = new EventEmitter();\n\n// First listener\nmyEmitter.on('event', function firstListener() {\n  console.log('Helloooo! first listener');\n});\n// Second listener\nmyEmitter.on('event', function secondListener(arg1, arg2) {\n  console.log(`event with parameters ${arg1}, ${arg2} in second listener`);\n});\n// Third listener\nmyEmitter.on('event', function thirdListener(...args) {\n  const parameters = args.join(', ');\n  console.log(`event with parameters ${parameters} in third listener`);\n});\n\nconsole.log(myEmitter.listeners('event'));\n\nmyEmitter.emit('event', 1, 2, 3, 4, 5);\n\n// Prints:\n// [\n//   [Function: firstListener],\n//   [Function: secondListener],\n//   [Function: thirdListener]\n// ]\n// Helloooo! first listener\n// event with parameters 1, 2 in second listener\n// event with parameters 1, 2, 3, 4, 5 in third listener\n```","summary":"Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst myEmitter = new EventEmitter();\n\n// First listener\nmyEmitter.on('event', function firstListener() {\n  console.log('Helloooo! first listener');\n});\n// Second listener\nmyEmitter.on('event', function secondListener(arg1, arg2) {\n  console.log(`event with parameters ${arg1}, ${arg2} in second listener`);\n});\n// Third listener\nmyEmitter.on('event', function thirdListener(...args) {\n  const parameters = args.join(', ');\n  console.log(`event with parameters ${parameters} in third listener`);\n});\n\nconsole.log(myEmitter.listeners('event'));\n\nmyEmitter.emit('event', 1, 2, 3, 4, 5);\n\n// Prints:\n// [\n//   [Function: firstListener],\n//   [Function: secondListener],\n//   [Function: thirdListener]\n// ]\n// Helloooo! first listener\n// event with parameters 1, 2 in second listener\n// event with parameters 1, 2, 3, 4, 5 in third listener"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst myEmitter = new EventEmitter();\n\n// First listener\nmyEmitter.on('event', function firstListener() {\n  console.log('Helloooo! first listener');\n});\n// Second listener\nmyEmitter.on('event', function secondListener(arg1, arg2) {\n  console.log(`event with parameters ${arg1}, ${arg2} in second listener`);\n});\n// Third listener\nmyEmitter.on('event', function thirdListener(...args) {\n  const parameters = args.join(', ');\n  console.log(`event with parameters ${parameters} in third listener`);\n});\n\nconsole.log(myEmitter.listeners('event'));\n\nmyEmitter.emit('event', 1, 2, 3, 4, 5);\n\n// Prints:\n// [\n//   [Function: firstListener],\n//   [Function: secondListener],\n//   [Function: thirdListener]\n// ]\n// Helloooo! first listener\n// event with parameters 1, 2 in second listener\n// event with parameters 1, 2, 3, 4, 5 in third listener"}],"children":[]},{"kind":"method","id":"emittereventnames","name":"eventNames","title":"`emitter.eventNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v6.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[] | symbol[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":11,"end":17}]},"description":""}},"description":"Returns an array listing the events for which the emitter has registered\nlisteners.\n\n```mjs\nimport { EventEmitter } from 'node:events';\n\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => {});\nmyEE.on('bar', () => {});\n\nconst sym = Symbol('symbol');\nmyEE.on(sym, () => {});\n\nconsole.log(myEE.eventNames());\n// Prints: [ 'foo', 'bar', Symbol(symbol) ]\n```\n\n```cjs\nconst EventEmitter = require('node:events');\n\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => {});\nmyEE.on('bar', () => {});\n\nconst sym = Symbol('symbol');\nmyEE.on(sym, () => {});\n\nconsole.log(myEE.eventNames());\n// Prints: [ 'foo', 'bar', Symbol(symbol) ]\n```","summary":"Returns an array listing the events for which the emitter has registered listeners.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\n\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => {});\nmyEE.on('bar', () => {});\n\nconst sym = Symbol('symbol');\nmyEE.on(sym, () => {});\n\nconsole.log(myEE.eventNames());\n// Prints: [ 'foo', 'bar', Symbol(symbol) ]"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\n\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => {});\nmyEE.on('bar', () => {});\n\nconst sym = Symbol('symbol');\nmyEE.on(sym, () => {});\n\nconsole.log(myEE.eventNames());\n// Prints: [ 'foo', 'bar', Symbol(symbol) ]"}],"children":[]},{"kind":"method","id":"emittergetmaxlisteners","name":"getMaxListeners","title":"`emitter.getMaxListeners()`","scope":"module","overloadOf":null,"stability":null,"added":["v1.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":""}},"description":"Returns the current max listener value for the `EventEmitter` which is either\nset by [`emitter.setMaxListeners(n)`](#emittersetmaxlistenersn) or defaults to\n[`events.defaultMaxListeners`](#eventsdefaultmaxlisteners).","summary":"Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to `events.defaultMaxListeners`.","examples":[],"children":[]},{"kind":"method","id":"emitterlistenercounteventname-listener","name":"listenerCount","title":"`emitter.listenerCount(eventName[, listener])`","scope":"module","overloadOf":null,"stability":null,"added":["v3.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.8.0","v18.16.0"],"prUrl":"https://github.com/nodejs/node/pull/46523","commit":null,"description":"Added the `listener` argument."}],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event being listened for","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The event handler function","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":""}},"description":"Returns the number of listeners listening for the event named `eventName`.\nIf `listener` is provided, it will return how many times the listener is found\nin the list of the listeners of the event.","summary":"Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event.","examples":[],"children":[]},{"kind":"method","id":"emitterlistenerseventname","name":"listeners","title":"`emitter.listeners(eventName)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v7.0.0"],"prUrl":"https://github.com/nodejs/node/pull/6881","commit":null,"description":"For listeners attached using `.once()` this returns the original listeners instead of wrapper functions now."}],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function[]","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":""}},"description":"Returns a copy of the array of listeners for the event named `eventName`.\n\n```js\nserver.on('connection', (stream) => {\n  console.log('someone connected!');\n});\nconsole.log(util.inspect(server.listeners('connection')));\n// Prints: [ [Function] ]\n```","summary":"Returns a copy of the array of listeners for the event named `eventName`.","examples":[{"language":"js","displayName":null,"code":"server.on('connection', (stream) => {\n  console.log('someone connected!');\n});\nconsole.log(util.inspect(server.listeners('connection')));\n// Prints: [ [Function] ]"}],"children":[]},{"kind":"method","id":"emitteroffeventname-listener","name":"off","title":"`emitter.off(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v10.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Alias for [`emitter.removeListener()`](#emitterremovelistenereventname-listener).","summary":"Alias for `emitter.removeListener()`.","examples":[],"children":[]},{"kind":"method","id":"emitteroneventname-listener","name":"on","title":"`emitter.on(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.101"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The callback function","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Adds the `listener` function to the end of the listeners array for the\nevent named `eventName`. No checks are made to see if the `listener` has\nalready been added. Multiple calls passing the same combination of `eventName`\nand `listener` will result in the `listener` being added, and called, multiple\ntimes.\n\n```js\nserver.on('connection', (stream) => {\n  console.log('someone connected!');\n});\n```\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.\n\nBy default, event listeners are invoked in the order they are added. The\n`emitter.prependListener()` method can be used as an alternative to add the\nevent listener to the beginning of the listeners array.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => console.log('a'));\nmyEE.prependListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => console.log('a'));\nmyEE.prependListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a\n```","summary":"Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times.","examples":[{"language":"js","displayName":null,"code":"server.on('connection', (stream) => {\n  console.log('someone connected!');\n});"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => console.log('a'));\nmyEE.prependListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst myEE = new EventEmitter();\nmyEE.on('foo', () => console.log('a'));\nmyEE.prependListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a"}],"children":[]},{"kind":"method","id":"emitteronceeventname-listener","name":"once","title":"`emitter.once(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The callback function","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Adds a **one-time** `listener` function for the event named `eventName`. The\nnext time `eventName` is triggered, this listener is removed and then invoked.\n\n```js\nserver.once('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});\n```\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.\n\nBy default, event listeners are invoked in the order they are added. The\n`emitter.prependOnceListener()` method can be used as an alternative to add the\nevent listener to the beginning of the listeners array.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst myEE = new EventEmitter();\nmyEE.once('foo', () => console.log('a'));\nmyEE.prependOnceListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst myEE = new EventEmitter();\nmyEE.once('foo', () => console.log('a'));\nmyEE.prependOnceListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a\n```","summary":"Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked.","examples":[{"language":"js","displayName":null,"code":"server.once('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst myEE = new EventEmitter();\nmyEE.once('foo', () => console.log('a'));\nmyEE.prependOnceListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst myEE = new EventEmitter();\nmyEE.once('foo', () => console.log('a'));\nmyEE.prependOnceListener('foo', () => console.log('b'));\nmyEE.emit('foo');\n// Prints:\n//   b\n//   a"}],"children":[]},{"kind":"method","id":"emitterprependlistenereventname-listener","name":"prependListener","title":"`emitter.prependListener(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v6.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The callback function","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Adds the `listener` function to the *beginning* of the listeners array for the\nevent named `eventName`. No checks are made to see if the `listener` has\nalready been added. Multiple calls passing the same combination of `eventName`\nand `listener` will result in the `listener` being added, and called, multiple\ntimes.\n\n```js\nserver.prependListener('connection', (stream) => {\n  console.log('someone connected!');\n});\n```\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.","summary":"Adds the `listener` function to the _beginning_ of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times.","examples":[{"language":"js","displayName":null,"code":"server.prependListener('connection', (stream) => {\n  console.log('someone connected!');\n});"}],"children":[]},{"kind":"method","id":"emitterprependoncelistenereventname-listener","name":"prependOnceListener","title":"`emitter.prependOnceListener(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v6.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The callback function","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Adds a **one-time** `listener` function for the event named `eventName` to the\n*beginning* of the listeners array. The next time `eventName` is triggered, this\nlistener is removed, and then invoked.\n\n```js\nserver.prependOnceListener('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});\n```\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.","summary":"Adds a **one-time** `listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked.","examples":[{"language":"js","displayName":null,"code":"server.prependOnceListener('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});"}],"children":[]},{"kind":"method","id":"emitterremovealllistenerseventname","name":"removeAllListeners","title":"`emitter.removeAllListeners([eventName])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Removes all listeners, or those of the specified `eventName`.\n\nIt is bad practice to remove listeners added elsewhere in the code,\nparticularly when the `EventEmitter` instance was created by some other\ncomponent or module (e.g. sockets or file streams).\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.","summary":"Removes all listeners, or those of the specified `eventName`.","examples":[],"children":[]},{"kind":"method","id":"emitterremovelistenereventname-listener","name":"removeListener","title":"`emitter.removeListener(eventName, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.26"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"Removes the specified `listener` from the listener array for the event named\n`eventName`.\n\n```js\nconst callback = (stream) => {\n  console.log('someone connected!');\n};\nserver.on('connection', callback);\n// ...\nserver.removeListener('connection', callback);\n```\n\n`removeListener()` will remove, at most, one instance of a listener from the\nlistener array. If any single listener has been added multiple times to the\nlistener array for the specified `eventName`, then `removeListener()` must be\ncalled multiple times to remove each instance.\n\nOnce an event is emitted, all listeners attached to it at the\ntime of emitting are called in order. This implies that any\n`removeListener()` or `removeAllListeners()` calls *after* emitting and\n*before* the last listener finishes execution will not remove them from\n`emit()` in progress. Subsequent events behave as expected.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\n\nconst callbackA = () => {\n  console.log('A');\n  myEmitter.removeListener('event', callbackB);\n};\n\nconst callbackB = () => {\n  console.log('B');\n};\n\nmyEmitter.on('event', callbackA);\n\nmyEmitter.on('event', callbackB);\n\n// callbackA removes listener callbackB but it will still be called.\n// Internal listener array at time of emit [callbackA, callbackB]\nmyEmitter.emit('event');\n// Prints:\n//   A\n//   B\n\n// callbackB is now removed.\n// Internal listener array [callbackA]\nmyEmitter.emit('event');\n// Prints:\n//   A\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\n\nconst callbackA = () => {\n  console.log('A');\n  myEmitter.removeListener('event', callbackB);\n};\n\nconst callbackB = () => {\n  console.log('B');\n};\n\nmyEmitter.on('event', callbackA);\n\nmyEmitter.on('event', callbackB);\n\n// callbackA removes listener callbackB but it will still be called.\n// Internal listener array at time of emit [callbackA, callbackB]\nmyEmitter.emit('event');\n// Prints:\n//   A\n//   B\n\n// callbackB is now removed.\n// Internal listener array [callbackA]\nmyEmitter.emit('event');\n// Prints:\n//   A\n```\n\nBecause listeners are managed using an internal array, calling this will\nchange the position indexes of any listener registered *after* the listener\nbeing removed. This will not impact the order in which listeners are called,\nbut it means that any copies of the listener array as returned by\nthe `emitter.listeners()` method will need to be recreated.\n\nWhen a single function has been added as a handler multiple times for a single\nevent (as in the example below), `removeListener()` will remove the most\nrecently added instance. In the example the `once('ping')`\nlistener is removed:\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst ee = new EventEmitter();\n\nfunction pong() {\n  console.log('pong');\n}\n\nee.on('ping', pong);\nee.once('ping', pong);\nee.removeListener('ping', pong);\n\nee.emit('ping');\nee.emit('ping');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst ee = new EventEmitter();\n\nfunction pong() {\n  console.log('pong');\n}\n\nee.on('ping', pong);\nee.once('ping', pong);\nee.removeListener('ping', pong);\n\nee.emit('ping');\nee.emit('ping');\n```\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.","summary":"Removes the specified `listener` from the listener array for the event named `eventName`.","examples":[{"language":"js","displayName":null,"code":"const callback = (stream) => {\n  console.log('someone connected!');\n};\nserver.on('connection', callback);\n// ...\nserver.removeListener('connection', callback);"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\n\nconst callbackA = () => {\n  console.log('A');\n  myEmitter.removeListener('event', callbackB);\n};\n\nconst callbackB = () => {\n  console.log('B');\n};\n\nmyEmitter.on('event', callbackA);\n\nmyEmitter.on('event', callbackB);\n\n// callbackA removes listener callbackB but it will still be called.\n// Internal listener array at time of emit [callbackA, callbackB]\nmyEmitter.emit('event');\n// Prints:\n//   A\n//   B\n\n// callbackB is now removed.\n// Internal listener array [callbackA]\nmyEmitter.emit('event');\n// Prints:\n//   A"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nclass MyEmitter extends EventEmitter {}\nconst myEmitter = new MyEmitter();\n\nconst callbackA = () => {\n  console.log('A');\n  myEmitter.removeListener('event', callbackB);\n};\n\nconst callbackB = () => {\n  console.log('B');\n};\n\nmyEmitter.on('event', callbackA);\n\nmyEmitter.on('event', callbackB);\n\n// callbackA removes listener callbackB but it will still be called.\n// Internal listener array at time of emit [callbackA, callbackB]\nmyEmitter.emit('event');\n// Prints:\n//   A\n//   B\n\n// callbackB is now removed.\n// Internal listener array [callbackA]\nmyEmitter.emit('event');\n// Prints:\n//   A"},{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst ee = new EventEmitter();\n\nfunction pong() {\n  console.log('pong');\n}\n\nee.on('ping', pong);\nee.once('ping', pong);\nee.removeListener('ping', pong);\n\nee.emit('ping');\nee.emit('ping');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst ee = new EventEmitter();\n\nfunction pong() {\n  console.log('pong');\n}\n\nee.on('ping', pong);\nee.once('ping', pong);\nee.removeListener('ping', pong);\n\nee.emit('ping');\nee.emit('ping');"}],"children":[]},{"kind":"method","id":"emittersetmaxlistenersn","name":"setMaxListeners","title":"`emitter.setMaxListeners(n)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"n","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":""}},"description":"By default `EventEmitter`s will print a warning if more than `10` listeners are\nadded for a particular event. This is a useful default that helps finding\nmemory leaks. The `emitter.setMaxListeners()` method allows the limit to be\nmodified for this specific `EventEmitter` instance. The value can be set to\n`Infinity` (or `0`) to indicate an unlimited number of listeners.\n\nReturns a reference to the `EventEmitter`, so that calls can be chained.","summary":"By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.","examples":[],"children":[]},{"kind":"method","id":"emitterrawlistenerseventname","name":"rawListeners","title":"`emitter.rawListeners(eventName)`","scope":"module","overloadOf":null,"stability":null,"added":["v9.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function[]","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":""}},"description":"Returns a copy of the array of listeners for the event named `eventName`,\nincluding any wrappers (such as those created by `.once()`).\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst emitter = new EventEmitter();\nemitter.once('log', () => console.log('log once'));\n\n// Returns a new Array with a function `onceWrapper` which has a property\n// `listener` which contains the original listener bound above\nconst listeners = emitter.rawListeners('log');\nconst logFnWrapper = listeners[0];\n\n// Logs \"log once\" to the console and does not unbind the `once` event\nlogFnWrapper.listener();\n\n// Logs \"log once\" to the console and removes the listener\nlogFnWrapper();\n\nemitter.on('log', () => console.log('log persistently'));\n// Will return a new Array with a single function bound by `.on()` above\nconst newListeners = emitter.rawListeners('log');\n\n// Logs \"log persistently\" twice\nnewListeners[0]();\nemitter.emit('log');\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst emitter = new EventEmitter();\nemitter.once('log', () => console.log('log once'));\n\n// Returns a new Array with a function `onceWrapper` which has a property\n// `listener` which contains the original listener bound above\nconst listeners = emitter.rawListeners('log');\nconst logFnWrapper = listeners[0];\n\n// Logs \"log once\" to the console and does not unbind the `once` event\nlogFnWrapper.listener();\n\n// Logs \"log once\" to the console and removes the listener\nlogFnWrapper();\n\nemitter.on('log', () => console.log('log persistently'));\n// Will return a new Array with a single function bound by `.on()` above\nconst newListeners = emitter.rawListeners('log');\n\n// Logs \"log persistently\" twice\nnewListeners[0]();\nemitter.emit('log');\n```","summary":"Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`).","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst emitter = new EventEmitter();\nemitter.once('log', () => console.log('log once'));\n\n// Returns a new Array with a function `onceWrapper` which has a property\n// `listener` which contains the original listener bound above\nconst listeners = emitter.rawListeners('log');\nconst logFnWrapper = listeners[0];\n\n// Logs \"log once\" to the console and does not unbind the `once` event\nlogFnWrapper.listener();\n\n// Logs \"log once\" to the console and removes the listener\nlogFnWrapper();\n\nemitter.on('log', () => console.log('log persistently'));\n// Will return a new Array with a single function bound by `.on()` above\nconst newListeners = emitter.rawListeners('log');\n\n// Logs \"log persistently\" twice\nnewListeners[0]();\nemitter.emit('log');"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst emitter = new EventEmitter();\nemitter.once('log', () => console.log('log once'));\n\n// Returns a new Array with a function `onceWrapper` which has a property\n// `listener` which contains the original listener bound above\nconst listeners = emitter.rawListeners('log');\nconst logFnWrapper = listeners[0];\n\n// Logs \"log once\" to the console and does not unbind the `once` event\nlogFnWrapper.listener();\n\n// Logs \"log once\" to the console and removes the listener\nlogFnWrapper();\n\nemitter.on('log', () => console.log('log persistently'));\n// Will return a new Array with a single function bound by `.on()` above\nconst newListeners = emitter.rawListeners('log');\n\n// Logs \"log persistently\" twice\nnewListeners[0]();\nemitter.emit('log');"}],"children":[]},{"kind":"method","id":"emittersymbolfornodejsrejectionerr-eventname-args","name":"[Symbol.for('nodejs.rejection')]","title":"`emitter[Symbol.for('nodejs.rejection')](err, eventName[, ...args])`","scope":"module","overloadOf":null,"stability":null,"added":["v13.4.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.4.0","v16.14.0"],"prUrl":"https://github.com/nodejs/node/pull/41267","commit":null,"description":"No longer experimental."}],"signature":{"parameters":[{"name":"err","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"args","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":true,"rest":true,"properties":[]}],"returns":null},"description":"The `Symbol.for('nodejs.rejection')` method is called in case a\npromise rejection happens when emitting an event and\n[`captureRejections`](#capture-rejections-of-promises) is enabled on the emitter.\nIt is possible to use [`events.captureRejectionSymbol`](#eventscapturerejectionsymbol) in\nplace of `Symbol.for('nodejs.rejection')`.\n\n```mjs\nimport { EventEmitter, captureRejectionSymbol } from 'node:events';\n\nclass MyClass extends EventEmitter {\n  constructor() {\n    super({ captureRejections: true });\n  }\n\n  [captureRejectionSymbol](err, event, ...args) {\n    console.log('rejection happened for', event, 'with', err, ...args);\n    this.destroy(err);\n  }\n\n  destroy(err) {\n    // Tear the resource down here.\n  }\n}\n```\n\n```cjs\nconst { EventEmitter, captureRejectionSymbol } = require('node:events');\n\nclass MyClass extends EventEmitter {\n  constructor() {\n    super({ captureRejections: true });\n  }\n\n  [captureRejectionSymbol](err, event, ...args) {\n    console.log('rejection happened for', event, 'with', err, ...args);\n    this.destroy(err);\n  }\n\n  destroy(err) {\n    // Tear the resource down here.\n  }\n}\n```","summary":"The `Symbol.for('nodejs.rejection')` method is called in case a promise rejection happens when emitting an event and `captureRejections` is enabled on the emitter. It is possible to use `events.captureRejectionSymbol` in place of `Symbol.for('nodejs.rejection')`.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter, captureRejectionSymbol } from 'node:events';\n\nclass MyClass extends EventEmitter {\n  constructor() {\n    super({ captureRejections: true });\n  }\n\n  [captureRejectionSymbol](err, event, ...args) {\n    console.log('rejection happened for', event, 'with', err, ...args);\n    this.destroy(err);\n  }\n\n  destroy(err) {\n    // Tear the resource down here.\n  }\n}"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, captureRejectionSymbol } = require('node:events');\n\nclass MyClass extends EventEmitter {\n  constructor() {\n    super({ captureRejections: true });\n  }\n\n  [captureRejectionSymbol](err, event, ...args) {\n    console.log('rejection happened for', event, 'with', err, ...args);\n    this.destroy(err);\n  }\n\n  destroy(err) {\n    // Tear the resource down here.\n  }\n}"}],"children":[]}]},{"kind":"property","id":"eventsdefaultmaxlisteners","name":"defaultMaxListeners","title":"`events.defaultMaxListeners`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"By default, a maximum of `10` listeners can be registered for any single\nevent. This limit can be changed for individual `EventEmitter` instances\nusing the [`emitter.setMaxListeners(n)`](#emittersetmaxlistenersn) method. To change the default\nfor *all* `EventEmitter` instances, the `events.defaultMaxListeners`\nproperty can be used. If this value is not a positive number, a `RangeError`\nis thrown.\n\nTake caution when setting the `events.defaultMaxListeners` because the\nchange affects *all* `EventEmitter` instances, including those created before\nthe change is made. However, calling [`emitter.setMaxListeners(n)`](#emittersetmaxlistenersn) still has\nprecedence over `events.defaultMaxListeners`.\n\nThis is not a hard limit. The `EventEmitter` instance will allow\nmore listeners to be added but will output a trace warning to stderr indicating\nthat a \"possible EventEmitter memory leak\" has been detected. For any single\n`EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()`\nmethods can be used to temporarily avoid this warning:\n\n`defaultMaxListeners` has no effect on `AbortSignal` instances. While it is\nstill possible to use [`emitter.setMaxListeners(n)`](#emittersetmaxlistenersn) to set a warning limit\nfor individual `AbortSignal` instances, per default `AbortSignal` instances will not warn.\n\n```mjs\nimport { EventEmitter } from 'node:events';\nconst emitter = new EventEmitter();\nemitter.setMaxListeners(emitter.getMaxListeners() + 1);\nemitter.once('event', () => {\n  // do stuff\n  emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));\n});\n```\n\n```cjs\nconst EventEmitter = require('node:events');\nconst emitter = new EventEmitter();\nemitter.setMaxListeners(emitter.getMaxListeners() + 1);\nemitter.once('event', () => {\n  // do stuff\n  emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));\n});\n```\n\nThe [`--trace-warnings`](cli.html#--trace-warnings) command-line flag can be used to display the\nstack trace for such warnings.\n\nThe emitted warning can be inspected with [`process.on('warning')`](process.html#event-warning) and will\nhave the additional `emitter`, `type`, and `count` properties, referring to\nthe event emitter instance, the event's name and the number of attached\nlisteners, respectively.\nIts `name` property is set to `'MaxListenersExceededWarning'`.","summary":"By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for _all_ `EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter } from 'node:events';\nconst emitter = new EventEmitter();\nemitter.setMaxListeners(emitter.getMaxListeners() + 1);\nemitter.once('event', () => {\n  // do stuff\n  emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));\n});"},{"language":"cjs","displayName":null,"code":"const EventEmitter = require('node:events');\nconst emitter = new EventEmitter();\nemitter.setMaxListeners(emitter.getMaxListeners() + 1);\nemitter.once('event', () => {\n  // do stuff\n  emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));\n});"}],"children":[]},{"kind":"property","id":"eventserrormonitor","name":"errorMonitor","title":"`events.errorMonitor`","scope":"module","overloadOf":null,"stability":null,"added":["v13.6.0","v12.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"This symbol shall be used to install a listener for only monitoring `'error'`\nevents. Listeners installed using this symbol are called before the regular\n`'error'` listeners are called.\n\nInstalling a listener using this symbol does not change the behavior once an\n`'error'` event is emitted. Therefore, the process will still crash if no\nregular `'error'` listener is installed.","summary":"This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called.","examples":[],"children":[]},{"kind":"method","id":"eventsgeteventlistenersemitterortarget-eventname","name":"getEventListeners","title":"`events.getEventListeners(emitterOrTarget, eventName)`","scope":"module","overloadOf":null,"stability":null,"added":["v15.2.0","v14.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"emitterOrTarget","type":{"text":"EventEmitter | EventTarget","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12},{"name":"EventTarget","href":"events.html#class-eventtarget","start":15,"end":26}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function[]","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":""}},"description":"Returns a copy of the array of listeners for the event named `eventName`.\n\nFor `EventEmitter`s this behaves exactly the same as calling `.listeners` on\nthe emitter.\n\nFor `EventTarget`s this is the only way to get the event listeners for the\nevent target. This is useful for debugging and diagnostic purposes.\n\n```mjs\nimport { getEventListeners, EventEmitter } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  const listener = () => console.log('Events are fun');\n  ee.on('foo', listener);\n  console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]\n}\n{\n  const et = new EventTarget();\n  const listener = () => console.log('Events are fun');\n  et.addEventListener('foo', listener);\n  console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]\n}\n```\n\n```cjs\nconst { getEventListeners, EventEmitter } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  const listener = () => console.log('Events are fun');\n  ee.on('foo', listener);\n  console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]\n}\n{\n  const et = new EventTarget();\n  const listener = () => console.log('Events are fun');\n  et.addEventListener('foo', listener);\n  console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]\n}\n```","summary":"Returns a copy of the array of listeners for the event named `eventName`.","examples":[{"language":"mjs","displayName":null,"code":"import { getEventListeners, EventEmitter } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  const listener = () => console.log('Events are fun');\n  ee.on('foo', listener);\n  console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]\n}\n{\n  const et = new EventTarget();\n  const listener = () => console.log('Events are fun');\n  et.addEventListener('foo', listener);\n  console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]\n}"},{"language":"cjs","displayName":null,"code":"const { getEventListeners, EventEmitter } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  const listener = () => console.log('Events are fun');\n  ee.on('foo', listener);\n  console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]\n}\n{\n  const et = new EventTarget();\n  const listener = () => console.log('Events are fun');\n  et.addEventListener('foo', listener);\n  console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]\n}"}],"children":[]},{"kind":"method","id":"eventsgetmaxlistenersemitterortarget","name":"getMaxListeners","title":"`events.getMaxListeners(emitterOrTarget)`","scope":"module","overloadOf":null,"stability":null,"added":["v19.9.0","v18.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"emitterOrTarget","type":{"text":"EventEmitter | EventTarget","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12},{"name":"EventTarget","href":"events.html#class-eventtarget","start":15,"end":26}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":""}},"description":"Returns the currently set max amount of listeners.\n\nFor `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on\nthe emitter.\n\nFor `EventTarget`s this is the only way to get the max event listeners for the\nevent target. If the number of event handlers on a single EventTarget exceeds\nthe max set, the EventTarget will print a warning.\n\n```mjs\nimport { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  console.log(getMaxListeners(ee)); // 10\n  setMaxListeners(11, ee);\n  console.log(getMaxListeners(ee)); // 11\n}\n{\n  const et = new EventTarget();\n  console.log(getMaxListeners(et)); // 10\n  setMaxListeners(11, et);\n  console.log(getMaxListeners(et)); // 11\n}\n```\n\n```cjs\nconst { getMaxListeners, setMaxListeners, EventEmitter } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  console.log(getMaxListeners(ee)); // 10\n  setMaxListeners(11, ee);\n  console.log(getMaxListeners(ee)); // 11\n}\n{\n  const et = new EventTarget();\n  console.log(getMaxListeners(et)); // 10\n  setMaxListeners(11, et);\n  console.log(getMaxListeners(et)); // 11\n}\n```","summary":"Returns the currently set max amount of listeners.","examples":[{"language":"mjs","displayName":null,"code":"import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  console.log(getMaxListeners(ee)); // 10\n  setMaxListeners(11, ee);\n  console.log(getMaxListeners(ee)); // 11\n}\n{\n  const et = new EventTarget();\n  console.log(getMaxListeners(et)); // 10\n  setMaxListeners(11, et);\n  console.log(getMaxListeners(et)); // 11\n}"},{"language":"cjs","displayName":null,"code":"const { getMaxListeners, setMaxListeners, EventEmitter } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  console.log(getMaxListeners(ee)); // 10\n  setMaxListeners(11, ee);\n  console.log(getMaxListeners(ee)); // 11\n}\n{\n  const et = new EventTarget();\n  console.log(getMaxListeners(et)); // 10\n  setMaxListeners(11, et);\n  console.log(getMaxListeners(et)); // 11\n}"}],"children":[]},{"kind":"method","id":"eventsonceemitter-name-options","name":"once","title":"`events.once(emitter, name[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v11.13.0","v10.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/34912","commit":null,"description":"The `signal` option is supported now."}],"signature":{"parameters":[{"name":"emitter","type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"name","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Can be used to cancel waiting for the event.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":""}},"description":"Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given\nevent or that is rejected if the `EventEmitter` emits `'error'` while waiting.\nThe `Promise` will resolve with an array of all the arguments emitted to the\ngiven event.\n\nThis method is intentionally generic and works with the web platform\n[EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special\n`'error'` event semantics and does not listen to the `'error'` event.\n\n```mjs\nimport { once, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ee = new EventEmitter();\n\nprocess.nextTick(() => {\n  ee.emit('myevent', 42);\n});\n\nconst [value] = await once(ee, 'myevent');\nconsole.log(value);\n\nconst err = new Error('kaboom');\nprocess.nextTick(() => {\n  ee.emit('error', err);\n});\n\ntry {\n  await once(ee, 'myevent');\n} catch (err) {\n  console.error('error happened', err);\n}\n```\n\n```cjs\nconst { once, EventEmitter } = require('node:events');\n\nasync function run() {\n  const ee = new EventEmitter();\n\n  process.nextTick(() => {\n    ee.emit('myevent', 42);\n  });\n\n  const [value] = await once(ee, 'myevent');\n  console.log(value);\n\n  const err = new Error('kaboom');\n  process.nextTick(() => {\n    ee.emit('error', err);\n  });\n\n  try {\n    await once(ee, 'myevent');\n  } catch (err) {\n    console.error('error happened', err);\n  }\n}\n\nrun();\n```\n\nThe special handling of the `'error'` event is only used when `events.once()`\nis used to wait for another event. If `events.once()` is used to wait for the\n'`error'` event itself, then it is treated as any other kind of event without\nspecial handling:\n\n```mjs\nimport { EventEmitter, once } from 'node:events';\n\nconst ee = new EventEmitter();\n\nonce(ee, 'error')\n  .then(([err]) => console.log('ok', err.message))\n  .catch((err) => console.error('error', err.message));\n\nee.emit('error', new Error('boom'));\n\n// Prints: ok boom\n```\n\n```cjs\nconst { EventEmitter, once } = require('node:events');\n\nconst ee = new EventEmitter();\n\nonce(ee, 'error')\n  .then(([err]) => console.log('ok', err.message))\n  .catch((err) => console.error('error', err.message));\n\nee.emit('error', new Error('boom'));\n\n// Prints: ok boom\n```\n\nAn {AbortSignal} can be used to cancel waiting for the event:\n\n```mjs\nimport { EventEmitter, once } from 'node:events';\n\nconst ee = new EventEmitter();\nconst ac = new AbortController();\n\nasync function foo(emitter, event, signal) {\n  try {\n    await once(emitter, event, { signal });\n    console.log('event emitted!');\n  } catch (error) {\n    if (error.name === 'AbortError') {\n      console.error('Waiting for the event was canceled!');\n    } else {\n      console.error('There was an error', error.message);\n    }\n  }\n}\n\nfoo(ee, 'foo', ac.signal);\nac.abort(); // Prints: Waiting for the event was canceled!\n```\n\n```cjs\nconst { EventEmitter, once } = require('node:events');\n\nconst ee = new EventEmitter();\nconst ac = new AbortController();\n\nasync function foo(emitter, event, signal) {\n  try {\n    await once(emitter, event, { signal });\n    console.log('event emitted!');\n  } catch (error) {\n    if (error.name === 'AbortError') {\n      console.error('Waiting for the event was canceled!');\n    } else {\n      console.error('There was an error', error.message);\n    }\n  }\n}\n\nfoo(ee, 'foo', ac.signal);\nac.abort(); // Prints: Waiting for the event was canceled!\n```","summary":"Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event.","examples":[{"language":"mjs","displayName":null,"code":"import { once, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ee = new EventEmitter();\n\nprocess.nextTick(() => {\n  ee.emit('myevent', 42);\n});\n\nconst [value] = await once(ee, 'myevent');\nconsole.log(value);\n\nconst err = new Error('kaboom');\nprocess.nextTick(() => {\n  ee.emit('error', err);\n});\n\ntry {\n  await once(ee, 'myevent');\n} catch (err) {\n  console.error('error happened', err);\n}"},{"language":"cjs","displayName":null,"code":"const { once, EventEmitter } = require('node:events');\n\nasync function run() {\n  const ee = new EventEmitter();\n\n  process.nextTick(() => {\n    ee.emit('myevent', 42);\n  });\n\n  const [value] = await once(ee, 'myevent');\n  console.log(value);\n\n  const err = new Error('kaboom');\n  process.nextTick(() => {\n    ee.emit('error', err);\n  });\n\n  try {\n    await once(ee, 'myevent');\n  } catch (err) {\n    console.error('error happened', err);\n  }\n}\n\nrun();"},{"language":"mjs","displayName":null,"code":"import { EventEmitter, once } from 'node:events';\n\nconst ee = new EventEmitter();\n\nonce(ee, 'error')\n  .then(([err]) => console.log('ok', err.message))\n  .catch((err) => console.error('error', err.message));\n\nee.emit('error', new Error('boom'));\n\n// Prints: ok boom"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, once } = require('node:events');\n\nconst ee = new EventEmitter();\n\nonce(ee, 'error')\n  .then(([err]) => console.log('ok', err.message))\n  .catch((err) => console.error('error', err.message));\n\nee.emit('error', new Error('boom'));\n\n// Prints: ok boom"},{"language":"mjs","displayName":null,"code":"import { EventEmitter, once } from 'node:events';\n\nconst ee = new EventEmitter();\nconst ac = new AbortController();\n\nasync function foo(emitter, event, signal) {\n  try {\n    await once(emitter, event, { signal });\n    console.log('event emitted!');\n  } catch (error) {\n    if (error.name === 'AbortError') {\n      console.error('Waiting for the event was canceled!');\n    } else {\n      console.error('There was an error', error.message);\n    }\n  }\n}\n\nfoo(ee, 'foo', ac.signal);\nac.abort(); // Prints: Waiting for the event was canceled!"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, once } = require('node:events');\n\nconst ee = new EventEmitter();\nconst ac = new AbortController();\n\nasync function foo(emitter, event, signal) {\n  try {\n    await once(emitter, event, { signal });\n    console.log('event emitted!');\n  } catch (error) {\n    if (error.name === 'AbortError') {\n      console.error('Waiting for the event was canceled!');\n    } else {\n      console.error('There was an error', error.message);\n    }\n  }\n}\n\nfoo(ee, 'foo', ac.signal);\nac.abort(); // Prints: Waiting for the event was canceled!"}],"children":[{"kind":"section","id":"caveats-when-awaiting-multiple-events","name":"Caveats when awaiting multiple events","title":"Caveats when awaiting multiple events","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"It is important to be aware of execution order when using the `events.once()`\nmethod to await multiple events.\n\nConventional event listeners are called synchronously when the event is\nemitted. This guarantees that execution will not proceed beyond the emitted\nevent until all listeners have finished executing.\n\nThe same is *not* true when awaiting Promises returned by `events.once()`.\nPromise tasks are not handled until after the current execution stack runs to\ncompletion, which means that multiple events could be emitted before\nasynchronous execution continues from the relevant `await` statement.\n\nAs a result, events can be \"missed\" if a series of `await events.once()`\nstatements is used to listen to multiple events, since there might be times\nwhere more than one event is emitted during the same phase of the event loop.\n(The same is true when using `process.nextTick()` to emit events, because the\ntasks queued by `process.nextTick()` are executed before Promise tasks.)\n\n```mjs\nimport { EventEmitter, once } from 'node:events';\nimport process from 'node:process';\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await once(myEE, 'foo');\n  console.log('foo');\n\n  // This Promise will never resolve, because the 'bar' event will\n  // have already been emitted before the next line is executed.\n  await once(myEE, 'bar');\n  console.log('bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));\n```\n\n```cjs\nconst { EventEmitter, once } = require('node:events');\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await once(myEE, 'foo');\n  console.log('foo');\n\n  // This Promise will never resolve, because the 'bar' event will\n  // have already been emitted before the next line is executed.\n  await once(myEE, 'bar');\n  console.log('bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));\n```\n\nTo catch multiple events, create all of the Promises *before* awaiting any of\nthem. This is usually made easier by using `Promise.all()`, `Promise.race()`,\nor `Promise.allSettled()`:\n\n```mjs\nimport { EventEmitter, once } from 'node:events';\nimport process from 'node:process';\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await Promise.all([\n    once(myEE, 'foo'),\n    once(myEE, 'bar'),\n  ]);\n  console.log('foo', 'bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));\n```\n\n```cjs\nconst { EventEmitter, once } = require('node:events');\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await Promise.all([\n    once(myEE, 'bar'),\n    once(myEE, 'foo'),\n  ]);\n  console.log('foo', 'bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));\n```","summary":"It is important to be aware of execution order when using the `events.once()` method to await multiple events.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter, once } from 'node:events';\nimport process from 'node:process';\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await once(myEE, 'foo');\n  console.log('foo');\n\n  // This Promise will never resolve, because the 'bar' event will\n  // have already been emitted before the next line is executed.\n  await once(myEE, 'bar');\n  console.log('bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, once } = require('node:events');\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await once(myEE, 'foo');\n  console.log('foo');\n\n  // This Promise will never resolve, because the 'bar' event will\n  // have already been emitted before the next line is executed.\n  await once(myEE, 'bar');\n  console.log('bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));"},{"language":"mjs","displayName":null,"code":"import { EventEmitter, once } from 'node:events';\nimport process from 'node:process';\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await Promise.all([\n    once(myEE, 'foo'),\n    once(myEE, 'bar'),\n  ]);\n  console.log('foo', 'bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, once } = require('node:events');\n\nconst myEE = new EventEmitter();\n\nasync function listen() {\n  await Promise.all([\n    once(myEE, 'bar'),\n    once(myEE, 'foo'),\n  ]);\n  console.log('foo', 'bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('foo');\n  myEE.emit('bar');\n});\n\nlisten().then(() => console.log('done'));"}],"children":[]}]},{"kind":"property","id":"eventscapturerejections","name":"captureRejections","title":"`events.captureRejections`","scope":"module","overloadOf":null,"stability":null,"added":["v13.4.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.4.0","v16.14.0"],"prUrl":"https://github.com/nodejs/node/pull/41267","commit":null,"description":"No longer experimental."}],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Change the default `captureRejections` option on all new `EventEmitter` objects.","summary":"Change the default `captureRejections` option on all new `EventEmitter` objects.","examples":[],"children":[]},{"kind":"property","id":"eventscapturerejectionsymbol","name":"captureRejectionSymbol","title":"`events.captureRejectionSymbol`","scope":"module","overloadOf":null,"stability":null,"added":["v13.4.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.4.0","v16.14.0"],"prUrl":"https://github.com/nodejs/node/pull/41267","commit":null,"description":"No longer experimental."}],"type":{"text":"symbol","links":[{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":0,"end":6}]},"default":null,"description":"`Symbol.for('nodejs.rejection')`\n\nSee how to write a custom [rejection handler](#emittersymbolfornodejsrejectionerr-eventname-args).","summary":"See how to write a custom rejection handler.","examples":[],"children":[]},{"kind":"method","id":"eventslistenercountemitterortarget-eventname","name":"listenerCount","title":"`events.listenerCount(emitterOrTarget, eventName)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.12"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v25.4.0","v24.14.0"],"prUrl":"https://github.com/nodejs/node/pull/60214","commit":null,"description":"Now accepts EventTarget arguments."},{"versions":["v25.4.0","v24.14.0"],"prUrl":"https://github.com/nodejs/node/pull/60214","commit":null,"description":"Deprecation revoked."},{"versions":["v3.2.0"],"prUrl":"https://github.com/nodejs/node/pull/2349","commit":null,"description":"Documentation-only deprecation."}],"signature":{"parameters":[{"name":"emitterOrTarget","type":{"text":"EventEmitter | EventTarget","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12},{"name":"EventTarget","href":"events.html#class-eventtarget","start":15,"end":26}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":""}},"description":"Returns the number of registered listeners for the event named `eventName`.\n\nFor `EventEmitter`s this behaves exactly the same as calling `.listenerCount`\non the emitter.\n\nFor `EventTarget`s this is the only way to obtain the listener count. This can\nbe useful for debugging and diagnostic purposes.\n\n```mjs\nimport { EventEmitter, listenerCount } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  ee.on('event', () => {});\n  ee.on('event', () => {});\n  console.log(listenerCount(ee, 'event')); // 2\n}\n{\n  const et = new EventTarget();\n  et.addEventListener('event', () => {});\n  et.addEventListener('event', () => {});\n  console.log(listenerCount(et, 'event')); // 2\n}\n```\n\n```cjs\nconst { EventEmitter, listenerCount } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  ee.on('event', () => {});\n  ee.on('event', () => {});\n  console.log(listenerCount(ee, 'event')); // 2\n}\n{\n  const et = new EventTarget();\n  et.addEventListener('event', () => {});\n  et.addEventListener('event', () => {});\n  console.log(listenerCount(et, 'event')); // 2\n}\n```","summary":"Returns the number of registered listeners for the event named `eventName`.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitter, listenerCount } from 'node:events';\n\n{\n  const ee = new EventEmitter();\n  ee.on('event', () => {});\n  ee.on('event', () => {});\n  console.log(listenerCount(ee, 'event')); // 2\n}\n{\n  const et = new EventTarget();\n  et.addEventListener('event', () => {});\n  et.addEventListener('event', () => {});\n  console.log(listenerCount(et, 'event')); // 2\n}"},{"language":"cjs","displayName":null,"code":"const { EventEmitter, listenerCount } = require('node:events');\n\n{\n  const ee = new EventEmitter();\n  ee.on('event', () => {});\n  ee.on('event', () => {});\n  console.log(listenerCount(ee, 'event')); // 2\n}\n{\n  const et = new EventTarget();\n  et.addEventListener('event', () => {});\n  et.addEventListener('event', () => {});\n  console.log(listenerCount(et, 'event')); // 2\n}"}],"children":[]},{"kind":"method","id":"eventsonemitter-eventname-options","name":"on","title":"`events.on(emitter, eventName[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v13.6.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v22.0.0","v20.13.0"],"prUrl":"https://github.com/nodejs/node/pull/52080","commit":null,"description":"Support `highWaterMark` and `lowWaterMark` options, For consistency. Old options are still supported."},{"versions":["v20.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41276","commit":null,"description":"The `close`, `highWatermark`, and `lowWatermark` options are supported now."}],"signature":{"parameters":[{"name":"emitter","type":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"eventName","type":{"text":"string | symbol","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"symbol","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type","start":9,"end":15}]},"description":"The name of the event being listened for","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Can be used to cancel awaiting events.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"close","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Names of events that will end the iteration.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"highWaterMark","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":"`Number.MAX_SAFE_INTEGER` The high watermark. The emitter is paused every time the size of events being buffered is higher than it. Supported only on emitters implementing `pause()` and `resume()` methods","optional":true,"rest":false,"properties":[]},{"name":"lowWaterMark","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":"`1` The low watermark. The emitter is resumed every time the size of events being buffered is lower than it. Supported only on emitters implementing `pause()` and `resume()` methods","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"AsyncIterator","links":[{"name":"AsyncIterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator","start":0,"end":13}]},"description":"that iterates `eventName` events emitted by the `emitter`"}},"description":"```mjs\nimport { on, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ee = new EventEmitter();\n\n// Emit later on\nprocess.nextTick(() => {\n  ee.emit('foo', 'bar');\n  ee.emit('foo', 42);\n});\n\nfor await (const event of on(ee, 'foo')) {\n  // The execution of this inner block is synchronous and it\n  // processes one event at a time (even with await). Do not use\n  // if concurrent execution is required.\n  console.log(event); // prints ['bar'] [42]\n}\n// Unreachable here\n```\n\n```cjs\nconst { on, EventEmitter } = require('node:events');\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo')) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();\n```\n\nReturns an `AsyncIterator` that iterates `eventName` events. It will throw\nif the `EventEmitter` emits `'error'`. It removes all listeners when\nexiting the loop. The `value` returned by each iteration is an array\ncomposed of the emitted event arguments.\n\nAn {AbortSignal} can be used to cancel waiting on events:\n\n```mjs\nimport { on, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ac = new AbortController();\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo', { signal: ac.signal })) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();\n\nprocess.nextTick(() => ac.abort());\n```\n\n```cjs\nconst { on, EventEmitter } = require('node:events');\n\nconst ac = new AbortController();\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo', { signal: ac.signal })) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();\n\nprocess.nextTick(() => ac.abort());\n```","summary":"Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments.","examples":[{"language":"mjs","displayName":null,"code":"import { on, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ee = new EventEmitter();\n\n// Emit later on\nprocess.nextTick(() => {\n  ee.emit('foo', 'bar');\n  ee.emit('foo', 42);\n});\n\nfor await (const event of on(ee, 'foo')) {\n  // The execution of this inner block is synchronous and it\n  // processes one event at a time (even with await). Do not use\n  // if concurrent execution is required.\n  console.log(event); // prints ['bar'] [42]\n}\n// Unreachable here"},{"language":"cjs","displayName":null,"code":"const { on, EventEmitter } = require('node:events');\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo')) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();"},{"language":"mjs","displayName":null,"code":"import { on, EventEmitter } from 'node:events';\nimport process from 'node:process';\n\nconst ac = new AbortController();\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo', { signal: ac.signal })) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();\n\nprocess.nextTick(() => ac.abort());"},{"language":"cjs","displayName":null,"code":"const { on, EventEmitter } = require('node:events');\n\nconst ac = new AbortController();\n\n(async () => {\n  const ee = new EventEmitter();\n\n  // Emit later on\n  process.nextTick(() => {\n    ee.emit('foo', 'bar');\n    ee.emit('foo', 42);\n  });\n\n  for await (const event of on(ee, 'foo', { signal: ac.signal })) {\n    // The execution of this inner block is synchronous and it\n    // processes one event at a time (even with await). Do not use\n    // if concurrent execution is required.\n    console.log(event); // prints ['bar'] [42]\n  }\n  // Unreachable here\n})();\n\nprocess.nextTick(() => ac.abort());"}],"children":[]},{"kind":"method","id":"eventssetmaxlistenersn-eventtargets","name":"setMaxListeners","title":"`events.setMaxListeners(n[, ...eventTargets])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"n","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"A non-negative number. The maximum number of listeners per\n`EventTarget` event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"eventTargets","type":null,"description":"","default":null,"optional":true,"rest":true,"properties":[]}],"returns":null},"description":"```mjs\nimport { setMaxListeners, EventEmitter } from 'node:events';\n\nconst target = new EventTarget();\nconst emitter = new EventEmitter();\n\nsetMaxListeners(5, target, emitter);\n```\n\n```cjs\nconst {\n  setMaxListeners,\n  EventEmitter,\n} = require('node:events');\n\nconst target = new EventTarget();\nconst emitter = new EventEmitter();\n\nsetMaxListeners(5, target, emitter);\n```","summary":"","examples":[{"language":"mjs","displayName":null,"code":"import { setMaxListeners, EventEmitter } from 'node:events';\n\nconst target = new EventTarget();\nconst emitter = new EventEmitter();\n\nsetMaxListeners(5, target, emitter);"},{"language":"cjs","displayName":null,"code":"const {\n  setMaxListeners,\n  EventEmitter,\n} = require('node:events');\n\nconst target = new EventTarget();\nconst emitter = new EventEmitter();\n\nsetMaxListeners(5, target, emitter);"}],"children":[]},{"kind":"method","id":"eventsaddabortlistenersignal-listener","name":"addAbortListener","title":"`events.addAbortListener(signal, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v20.5.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0","v22.16.0"],"prUrl":"https://github.com/nodejs/node/pull/57765","commit":null,"description":"Change stability index for this feature from Experimental to Stable."}],"signature":{"parameters":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Disposable","links":[{"name":"Disposable","href":"https://tc39.es/proposal-explicit-resource-management/#sec-disposable-interface","start":0,"end":10}]},"description":"A Disposable that removes the `abort` listener."}},"description":"Listens once to the `abort` event on the provided `signal`.\n\nListening to the `abort` event on abort signals is unsafe and may\nlead to resource leaks since another third party with the signal can\ncall [`e.stopImmediatePropagation()`](#eventstopimmediatepropagation). Unfortunately Node.js cannot change\nthis since it would violate the web standard. Additionally, the original\nAPI makes it easy to forget to remove listeners.\n\nThis API allows safely using `AbortSignal`s in Node.js APIs by solving these\ntwo issues by listening to the event such that `stopImmediatePropagation` does\nnot prevent the listener from running.\n\nReturns a disposable so that it may be unsubscribed from more easily.\n\n```cjs\nconst { addAbortListener } = require('node:events');\n\nfunction example(signal) {\n  signal.addEventListener('abort', (e) => e.stopImmediatePropagation());\n  // addAbortListener() returns a disposable, so the `using` keyword ensures\n  // the abort listener is automatically removed when this scope exits.\n  using _ = addAbortListener(signal, (e) => {\n    // Do something when signal is aborted.\n  });\n}\n```\n\n```mjs\nimport { addAbortListener } from 'node:events';\n\nfunction example(signal) {\n  signal.addEventListener('abort', (e) => e.stopImmediatePropagation());\n  // addAbortListener() returns a disposable, so the `using` keyword ensures\n  // the abort listener is automatically removed when this scope exits.\n  using _ = addAbortListener(signal, (e) => {\n    // Do something when signal is aborted.\n  });\n}\n```","summary":"Listens once to the `abort` event on the provided `signal`.","examples":[{"language":"cjs","displayName":null,"code":"const { addAbortListener } = require('node:events');\n\nfunction example(signal) {\n  signal.addEventListener('abort', (e) => e.stopImmediatePropagation());\n  // addAbortListener() returns a disposable, so the `using` keyword ensures\n  // the abort listener is automatically removed when this scope exits.\n  using _ = addAbortListener(signal, (e) => {\n    // Do something when signal is aborted.\n  });\n}"},{"language":"mjs","displayName":null,"code":"import { addAbortListener } from 'node:events';\n\nfunction example(signal) {\n  signal.addEventListener('abort', (e) => e.stopImmediatePropagation());\n  // addAbortListener() returns a disposable, so the `using` keyword ensures\n  // the abort listener is automatically removed when this scope exits.\n  using _ = addAbortListener(signal, (e) => {\n    // Do something when signal is aborted.\n  });\n}"}],"children":[]},{"kind":"class","id":"class-eventseventemitterasyncresource-extends-eventemitter","name":"EventEmitterAsyncResource","title":"Class: `events.EventEmitterAsyncResource extends EventEmitter`","scope":"module","overloadOf":null,"stability":null,"added":["v17.4.0","v16.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"EventEmitter","links":[]},"description":"Integrates `EventEmitter` with {AsyncResource} for `EventEmitter`s that\nrequire manual async tracking. Specifically, all events emitted by instances\nof `events.EventEmitterAsyncResource` will run within its [async context](async_context.html).\n\n```mjs\nimport { EventEmitterAsyncResource, EventEmitter } from 'node:events';\nimport { notStrictEqual, strictEqual } from 'node:assert';\nimport { executionAsyncId, triggerAsyncId } from 'node:async_hooks';\n\n// Async tracking tooling will identify this as 'Q'.\nconst ee1 = new EventEmitterAsyncResource({ name: 'Q' });\n\n// 'foo' listeners will run in the EventEmitters async context.\nee1.on('foo', () => {\n  strictEqual(executionAsyncId(), ee1.asyncId);\n  strictEqual(triggerAsyncId(), ee1.triggerAsyncId);\n});\n\nconst ee2 = new EventEmitter();\n\n// 'foo' listeners on ordinary EventEmitters that do not track async\n// context, however, run in the same async context as the emit().\nee2.on('foo', () => {\n  notStrictEqual(executionAsyncId(), ee2.asyncId);\n  notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);\n});\n\nPromise.resolve().then(() => {\n  ee1.emit('foo');\n  ee2.emit('foo');\n});\n```\n\n```cjs\nconst { EventEmitterAsyncResource, EventEmitter } = require('node:events');\nconst { notStrictEqual, strictEqual } = require('node:assert');\nconst { executionAsyncId, triggerAsyncId } = require('node:async_hooks');\n\n// Async tracking tooling will identify this as 'Q'.\nconst ee1 = new EventEmitterAsyncResource({ name: 'Q' });\n\n// 'foo' listeners will run in the EventEmitters async context.\nee1.on('foo', () => {\n  strictEqual(executionAsyncId(), ee1.asyncId);\n  strictEqual(triggerAsyncId(), ee1.triggerAsyncId);\n});\n\nconst ee2 = new EventEmitter();\n\n// 'foo' listeners on ordinary EventEmitters that do not track async\n// context, however, run in the same async context as the emit().\nee2.on('foo', () => {\n  notStrictEqual(executionAsyncId(), ee2.asyncId);\n  notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);\n});\n\nPromise.resolve().then(() => {\n  ee1.emit('foo');\n  ee2.emit('foo');\n});\n```\n\nThe `EventEmitterAsyncResource` class has the same methods and takes the\nsame options as `EventEmitter` and `AsyncResource` themselves.","summary":"Integrates `EventEmitter` with {AsyncResource} for `EventEmitter`s that require manual async tracking. Specifically, all events emitted by instances of `events.EventEmitterAsyncResource` will run within its async context.","examples":[{"language":"mjs","displayName":null,"code":"import { EventEmitterAsyncResource, EventEmitter } from 'node:events';\nimport { notStrictEqual, strictEqual } from 'node:assert';\nimport { executionAsyncId, triggerAsyncId } from 'node:async_hooks';\n\n// Async tracking tooling will identify this as 'Q'.\nconst ee1 = new EventEmitterAsyncResource({ name: 'Q' });\n\n// 'foo' listeners will run in the EventEmitters async context.\nee1.on('foo', () => {\n  strictEqual(executionAsyncId(), ee1.asyncId);\n  strictEqual(triggerAsyncId(), ee1.triggerAsyncId);\n});\n\nconst ee2 = new EventEmitter();\n\n// 'foo' listeners on ordinary EventEmitters that do not track async\n// context, however, run in the same async context as the emit().\nee2.on('foo', () => {\n  notStrictEqual(executionAsyncId(), ee2.asyncId);\n  notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);\n});\n\nPromise.resolve().then(() => {\n  ee1.emit('foo');\n  ee2.emit('foo');\n});"},{"language":"cjs","displayName":null,"code":"const { EventEmitterAsyncResource, EventEmitter } = require('node:events');\nconst { notStrictEqual, strictEqual } = require('node:assert');\nconst { executionAsyncId, triggerAsyncId } = require('node:async_hooks');\n\n// Async tracking tooling will identify this as 'Q'.\nconst ee1 = new EventEmitterAsyncResource({ name: 'Q' });\n\n// 'foo' listeners will run in the EventEmitters async context.\nee1.on('foo', () => {\n  strictEqual(executionAsyncId(), ee1.asyncId);\n  strictEqual(triggerAsyncId(), ee1.triggerAsyncId);\n});\n\nconst ee2 = new EventEmitter();\n\n// 'foo' listeners on ordinary EventEmitters that do not track async\n// context, however, run in the same async context as the emit().\nee2.on('foo', () => {\n  notStrictEqual(executionAsyncId(), ee2.asyncId);\n  notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);\n});\n\nPromise.resolve().then(() => {\n  ee1.emit('foo');\n  ee2.emit('foo');\n});"}],"children":[{"kind":"constructor","id":"new-eventseventemitterasyncresourceoptions","name":"EventEmitterAsyncResource","title":"`new events.EventEmitterAsyncResource([options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"captureRejections","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"It enables\n[automatic capturing of promise rejection](#capture-rejections-of-promises).","default":"false","optional":true,"rest":false,"properties":[]},{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The type of async event.","default":"new.target.name","optional":true,"rest":false,"properties":[]},{"name":"triggerAsyncId","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The ID of the execution context that created this\nasync event.","default":"executionAsyncId()","optional":true,"rest":false,"properties":[]},{"name":"requireManualDestroy","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, disables `emitDestroy`\nwhen the object is garbage collected. This usually does not need to be set\n(even if `emitDestroy` is called manually), unless the resource's `asyncId`\nis retrieved and the sensitive API's `emitDestroy` is called with it.\nWhen set to `false`, the `emitDestroy` call on garbage collection\nwill only take place if there is at least one active `destroy` hook.","default":"false","optional":true,"rest":false,"properties":[]}]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"eventemitterasyncresourceasyncid","name":"asyncId","title":"`eventemitterasyncresource.asyncId`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The unique `asyncId` assigned to the resource.","summary":"","examples":[],"children":[]},{"kind":"property","id":"eventemitterasyncresourceasyncresource","name":"asyncResource","title":"`eventemitterasyncresource.asyncResource`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"AsyncResource","links":[{"name":"AsyncResource","href":"async_hooks.html#class-asyncresource","start":0,"end":13}]},"default":null,"description":"The underlying {AsyncResource}.\n\nThe returned `AsyncResource` object has an additional `eventEmitter` property\nthat provides a reference to this `EventEmitterAsyncResource`.","summary":"The returned `AsyncResource` object has an additional `eventEmitter` property that provides a reference to this `EventEmitterAsyncResource`.","examples":[],"children":[]},{"kind":"method","id":"eventemitterasyncresourceemitdestroy","name":"emitDestroy","title":"`eventemitterasyncresource.emitDestroy()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Call all `destroy` hooks. This should only ever be called once. An error will\nbe thrown if it is called more than once. This **must** be manually called. If\nthe resource is left to be collected by the GC then the `destroy` hooks will\nnever be called.","summary":"Call all `destroy` hooks. This should only ever be called once. An error will be thrown if it is called more than once. This **must** be manually called. If the resource is left to be collected by the GC then the `destroy` hooks will never be called.","examples":[],"children":[]},{"kind":"property","id":"eventemitterasyncresourcetriggerasyncid","name":"triggerAsyncId","title":"`eventemitterasyncresource.triggerAsyncId`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The same `triggerAsyncId` that is passed to the\n`AsyncResource` constructor.\n\n<a id=\"event-target-and-event-api\"></a>","summary":"<a id=\"event-target-and-event-api\"></a>","examples":[],"children":[]}]},{"kind":"section","id":"eventtarget-and-event-api","name":"EventTarget and Event API","title":"`EventTarget` and `Event` API","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/37237","commit":null,"description":"changed EventTarget error handling."},{"versions":["v15.4.0"],"prUrl":"https://github.com/nodejs/node/pull/35949","commit":null,"description":"No longer experimental."},{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/35496","commit":null,"description":"The `EventTarget` and `Event` classes are now available as globals."}],"description":"The `EventTarget` and `Event` objects are a Node.js-specific implementation\nof the [`EventTarget` Web API](https://dom.spec.whatwg.org/#eventtarget) that are exposed by some Node.js core APIs.\n\n```js\nconst target = new EventTarget();\n\ntarget.addEventListener('foo', (event) => {\n  console.log('foo event happened!');\n});\n```","summary":"The `EventTarget` and `Event` objects are a Node.js-specific implementation of the `EventTarget` Web API that are exposed by some Node.js core APIs.","examples":[{"language":"js","displayName":null,"code":"const target = new EventTarget();\n\ntarget.addEventListener('foo', (event) => {\n  console.log('foo event happened!');\n});"}],"children":[{"kind":"section","id":"nodejs-eventtarget-vs-dom-eventtarget","name":"Node.js EventTarget vs. DOM EventTarget","title":"Node.js `EventTarget` vs. DOM `EventTarget`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"There are two key differences between the Node.js `EventTarget` and the\n[`EventTarget` Web API](https://dom.spec.whatwg.org/#eventtarget):\n\n1. Whereas DOM `EventTarget` instances *may* be hierarchical, there is no\n   concept of hierarchy and event propagation in Node.js. That is, an event\n   dispatched to an `EventTarget` does not propagate through a hierarchy of\n   nested target objects that may each have their own set of handlers for the\n   event.\n2. In the Node.js `EventTarget`, if an event listener is an async function\n   or returns a `Promise`, and the returned `Promise` rejects, the rejection\n   is automatically captured and handled the same way as a listener that\n   throws synchronously (see [`EventTarget` error handling](#eventtarget-error-handling) for details).","summary":"There are two key differences between the Node.js `EventTarget` and the `EventTarget` Web API:","examples":[],"children":[]},{"kind":"section","id":"nodeeventtarget-vs-eventemitter","name":"NodeEventTarget vs. EventEmitter","title":"`NodeEventTarget` vs. `EventEmitter`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `NodeEventTarget` object implements a modified subset of the\n`EventEmitter` API that allows it to closely *emulate* an `EventEmitter` in\ncertain situations. A `NodeEventTarget` is *not* an instance of `EventEmitter`\nand cannot be used in place of an `EventEmitter` in most cases.\n\n1. Unlike `EventEmitter`, any given `listener` can be registered at most once\n   per event `type`. Attempts to register a `listener` multiple times are\n   ignored.\n2. The `NodeEventTarget` does not emulate the full `EventEmitter` API.\n   Specifically the `prependListener()`, `prependOnceListener()`,\n   `rawListeners()`, and `errorMonitor` APIs are not emulated.\n   The `'newListener'` and `'removeListener'` events will also not be emitted.\n3. The `NodeEventTarget` does not implement any special default behavior\n   for events with type `'error'`.\n4. The `NodeEventTarget` supports `EventListener` objects as well as\n   functions as handlers for all event types.","summary":"The `NodeEventTarget` object implements a modified subset of the `EventEmitter` API that allows it to closely _emulate_ an `EventEmitter` in certain situations. A `NodeEventTarget` is _not_ an instance of `EventEmitter` and cannot be used in place of an `EventEmitter` in most cases.","examples":[],"children":[]},{"kind":"section","id":"event-listener","name":"Event listener","title":"Event listener","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Event listeners registered for an event `type` may either be JavaScript\nfunctions or objects with a `handleEvent` property whose value is a function.\n\nIn either case, the handler function is invoked with the `event` argument\npassed to the `eventTarget.dispatchEvent()` function.\n\nAsync functions may be used as event listeners. If an async handler function\nrejects, the rejection is captured and handled as described in\n[`EventTarget` error handling](#eventtarget-error-handling).\n\nAn error thrown by one handler function does not prevent the other handlers\nfrom being invoked.\n\nThe return value of a handler function is ignored.\n\nHandlers are always invoked in the order they were added.\n\nHandler functions may mutate the `event` object.\n\n```js\nfunction handler1(event) {\n  console.log(event.type);  // Prints 'foo'\n  event.a = 1;\n}\n\nasync function handler2(event) {\n  console.log(event.type);  // Prints 'foo'\n  console.log(event.a);  // Prints 1\n}\n\nconst handler3 = {\n  handleEvent(event) {\n    console.log(event.type);  // Prints 'foo'\n  },\n};\n\nconst handler4 = {\n  async handleEvent(event) {\n    console.log(event.type);  // Prints 'foo'\n  },\n};\n\nconst target = new EventTarget();\n\ntarget.addEventListener('foo', handler1);\ntarget.addEventListener('foo', handler2);\ntarget.addEventListener('foo', handler3);\ntarget.addEventListener('foo', handler4, { once: true });\n```","summary":"Event listeners registered for an event `type` may either be JavaScript functions or objects with a `handleEvent` property whose value is a function.","examples":[{"language":"js","displayName":null,"code":"function handler1(event) {\n  console.log(event.type);  // Prints 'foo'\n  event.a = 1;\n}\n\nasync function handler2(event) {\n  console.log(event.type);  // Prints 'foo'\n  console.log(event.a);  // Prints 1\n}\n\nconst handler3 = {\n  handleEvent(event) {\n    console.log(event.type);  // Prints 'foo'\n  },\n};\n\nconst handler4 = {\n  async handleEvent(event) {\n    console.log(event.type);  // Prints 'foo'\n  },\n};\n\nconst target = new EventTarget();\n\ntarget.addEventListener('foo', handler1);\ntarget.addEventListener('foo', handler2);\ntarget.addEventListener('foo', handler3);\ntarget.addEventListener('foo', handler4, { once: true });"}],"children":[]},{"kind":"section","id":"eventtarget-error-handling","name":"EventTarget error handling","title":"`EventTarget` error handling","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When a registered event listener throws (or returns a Promise that rejects),\nby default the error is treated as an uncaught exception on\n`process.nextTick()`. This means uncaught exceptions in `EventTarget`s will\nterminate the Node.js process by default.\n\nThrowing within an event listener will *not* stop the other registered handlers\nfrom being invoked.\n\nThe `EventTarget` does not implement any special default handling for `'error'`\ntype events like `EventEmitter`.\n\nCurrently errors are first forwarded to the `process.on('error')` event\nbefore reaching `process.on('uncaughtException')`. This behavior is\ndeprecated and will change in a future release to align `EventTarget` with\nother Node.js APIs. Any code relying on the `process.on('error')` event should\nbe aligned with the new behavior.","summary":"When a registered event listener throws (or returns a Promise that rejects), by default the error is treated as an uncaught exception on `process.nextTick()`. This means uncaught exceptions in `EventTarget`s will terminate the Node.js process by default.","examples":[],"children":[]},{"kind":"class","id":"class-event","name":"Event","title":"Class: `Event`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/35496","commit":null,"description":"The `Event` class is now available through the global object."}],"extends":null,"description":"The `Event` object is an adaptation of the [`Event` Web API](https://dom.spec.whatwg.org/#event). Instances\nare created internally by Node.js.","summary":"The `Event` object is an adaptation of the `Event` Web API. Instances are created internally by Node.js.","examples":[],"children":[{"kind":"property","id":"eventbubbles","name":"bubbles","title":"`event.bubbles`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Always returns `false`.\n\nThis is not used in Node.js and is provided purely for completeness.","summary":"This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventcancelbubble","name":"cancelBubble","title":"`event.cancelBubble`","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: Use [`event.stopPropagation()`](#eventstoppropagation) instead."},"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Alias for `event.stopPropagation()` if set to `true`. This is not used\nin Node.js and is provided purely for completeness.","summary":"Alias for `event.stopPropagation()` if set to `true`. This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventcancelable","name":"cancelable","title":"`event.cancelable`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"True if the event was created with the `cancelable` option.","summary":"","examples":[],"children":[]},{"kind":"property","id":"eventcomposed","name":"composed","title":"`event.composed`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Always returns `false`.\n\nThis is not used in Node.js and is provided purely for completeness.","summary":"This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"method","id":"eventcomposedpath","name":"composedPath","title":"`event.composedPath()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Returns an array containing the current `EventTarget` as the only entry or\nempty if the event is not being dispatched. This is not used in\nNode.js and is provided purely for completeness.","summary":"Returns an array containing the current `EventTarget` as the only entry or empty if the event is not being dispatched. This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventcurrenttarget","name":"currentTarget","title":"`event.currentTarget`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"default":null,"description":"The `EventTarget` dispatching the event.\n\nAlias for `event.target`.","summary":"Alias for `event.target`.","examples":[],"children":[]},{"kind":"property","id":"eventdefaultprevented","name":"defaultPrevented","title":"`event.defaultPrevented`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` if `cancelable` is `true` and `event.preventDefault()` has been\ncalled.","summary":"Is `true` if `cancelable` is `true` and `event.preventDefault()` has been called.","examples":[],"children":[]},{"kind":"property","id":"eventeventphase","name":"eventPhase","title":"`event.eventPhase`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"Returns `0` while an event is not being dispatched, `2` while\nit is being dispatched.\n\nThis is not used in Node.js and is provided purely for completeness.","summary":"This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"method","id":"eventiniteventtype-bubbles-cancelable","name":"initEvent","title":"`event.initEvent(type[, bubbles[, cancelable]])`","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: The WHATWG spec considers it deprecated and users\nshouldn't use it at all."},"added":["v19.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"bubbles","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"cancelable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Redundant with event constructors and incapable of setting `composed`.\nThis is not used in Node.js and is provided purely for completeness.","summary":"Redundant with event constructors and incapable of setting `composed`. This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventistrusted","name":"isTrusted","title":"`event.isTrusted`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The {AbortSignal} `\"abort\"` event is emitted with `isTrusted` set to `true`. The\nvalue is `false` in all other cases.","summary":"The {AbortSignal} `\"abort\"` event is emitted with `isTrusted` set to `true`. The value is `false` in all other cases.","examples":[],"children":[]},{"kind":"method","id":"eventpreventdefault","name":"preventDefault","title":"`event.preventDefault()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Sets the `defaultPrevented` property to `true` if `cancelable` is `true`.","summary":"Sets the `defaultPrevented` property to `true` if `cancelable` is `true`.","examples":[],"children":[]},{"kind":"property","id":"eventreturnvalue","name":"returnValue","title":"`event.returnValue`","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: Use [`event.defaultPrevented`](#eventdefaultprevented) instead."},"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"True if the event has not been canceled.\n\nThe value of `event.returnValue` is always the opposite of `event.defaultPrevented`.\nThis is not used in Node.js and is provided purely for completeness.","summary":"The value of `event.returnValue` is always the opposite of `event.defaultPrevented`. This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventsrcelement","name":"srcElement","title":"`event.srcElement`","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: Use [`event.target`](#eventtarget) instead."},"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"default":null,"description":"The `EventTarget` dispatching the event.\n\nAlias for `event.target`.","summary":"Alias for `event.target`.","examples":[],"children":[]},{"kind":"method","id":"eventstopimmediatepropagation","name":"stopImmediatePropagation","title":"`event.stopImmediatePropagation()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Stops the invocation of event listeners after the current one completes.","summary":"Stops the invocation of event listeners after the current one completes.","examples":[],"children":[]},{"kind":"method","id":"eventstoppropagation","name":"stopPropagation","title":"`event.stopPropagation()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"This is not used in Node.js and is provided purely for completeness.","summary":"This is not used in Node.js and is provided purely for completeness.","examples":[],"children":[]},{"kind":"property","id":"eventtarget","name":"target","title":"`event.target`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"default":null,"description":"The `EventTarget` dispatching the event.","summary":"","examples":[],"children":[]},{"kind":"property","id":"eventtimestamp","name":"timeStamp","title":"`event.timeStamp`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The millisecond timestamp when the `Event` object was created.","summary":"The millisecond timestamp when the `Event` object was created.","examples":[],"children":[]},{"kind":"property","id":"eventtype","name":"type","title":"`event.type`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The event type identifier.","summary":"The event type identifier.","examples":[],"children":[]}]},{"kind":"class","id":"class-eventtarget","name":"EventTarget","title":"Class: `EventTarget`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/35496","commit":null,"description":"The `EventTarget` class is now available through the global object."}],"extends":null,"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"eventtargetaddeventlistenertype-listener-options","name":"addEventListener","title":"`eventTarget.addEventListener(type, listener[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.4.0"],"prUrl":"https://github.com/nodejs/node/pull/36258","commit":null,"description":"add support for `signal` option."}],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"once","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"When `true`, the listener is automatically removed\nwhen it is first invoked.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"passive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"When `true`, serves as a hint that the listener will\nnot call the `Event` object's `preventDefault()` method.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"capture","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Not directly used by Node.js. Added for API\ncompleteness.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"The listener will be removed when the given\nAbortSignal object's `abort()` method is called.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"Adds a new handler for the `type` event. Any given `listener` is added\nonly once per `type` and per `capture` option value.\n\nIf the `once` option is `true`, the `listener` is removed after the\nnext time a `type` event is dispatched.\n\nThe `capture` option is not used by Node.js in any functional way other than\ntracking registered event listeners per the `EventTarget` specification.\nSpecifically, the `capture` option is used as part of the key when registering\na `listener`. Any individual `listener` may be added once with\n`capture = false`, and once with `capture = true`.\n\n```js\nfunction handler(event) {}\n\nconst target = new EventTarget();\ntarget.addEventListener('foo', handler, { capture: true });  // first\ntarget.addEventListener('foo', handler, { capture: false }); // second\n\n// Removes the second instance of handler\ntarget.removeEventListener('foo', handler);\n\n// Removes the first instance of handler\ntarget.removeEventListener('foo', handler, { capture: true });\n```","summary":"Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.","examples":[{"language":"js","displayName":null,"code":"function handler(event) {}\n\nconst target = new EventTarget();\ntarget.addEventListener('foo', handler, { capture: true });  // first\ntarget.addEventListener('foo', handler, { capture: false }); // second\n\n// Removes the second instance of handler\ntarget.removeEventListener('foo', handler);\n\n// Removes the first instance of handler\ntarget.removeEventListener('foo', handler, { capture: true });"}],"children":[]},{"kind":"method","id":"eventtargetdispatcheventevent","name":"dispatchEvent","title":"`eventTarget.dispatchEvent(event)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"event","type":{"text":"Event","links":[{"name":"Event","href":"events.html#class-event","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if either event's `cancelable` attribute value is\nfalse or its `preventDefault()` method was not invoked, otherwise `false`."}},"description":"Dispatches the `event` to the list of handlers for `event.type`.\n\nThe registered event listeners is synchronously invoked in the order they\nwere registered.","summary":"Dispatches the `event` to the list of handlers for `event.type`.","examples":[],"children":[]},{"kind":"method","id":"eventtargetremoveeventlistenertype-listener-options","name":"removeEventListener","title":"`eventTarget.removeEventListener(type, listener[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"capture","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"Removes the `listener` from the list of handlers for event `type`.","summary":"Removes the `listener` from the list of handlers for event `type`.","examples":[],"children":[]}]},{"kind":"class","id":"class-customevent","name":"CustomEvent","title":"Class: `CustomEvent`","scope":"module","overloadOf":null,"stability":null,"added":["v18.7.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v23.0.0"],"prUrl":"https://github.com/nodejs/node/pull/52723","commit":null,"description":"No longer experimental."},{"versions":["v22.1.0","v20.13.0"],"prUrl":"https://github.com/nodejs/node/pull/52618","commit":null,"description":"CustomEvent is now stable."},{"versions":["v19.0.0"],"prUrl":"https://github.com/nodejs/node/pull/44860","commit":null,"description":"No longer behind `--experimental-global-customevent` CLI flag."}],"extends":{"text":"Event","links":[{"name":"Event","href":"events.html#class-event","start":0,"end":5}]},"description":"The `CustomEvent` object is an adaptation of the [`CustomEvent` Web API](https://dom.spec.whatwg.org/#customevent).\nInstances are created internally by Node.js.","summary":"The `CustomEvent` object is an adaptation of the `CustomEvent` Web API. Instances are created internally by Node.js.","examples":[],"children":[{"kind":"property","id":"eventdetail","name":"detail","title":"`event.detail`","scope":"module","overloadOf":null,"stability":null,"added":["v18.7.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v22.1.0","v20.13.0"],"prUrl":"https://github.com/nodejs/node/pull/52618","commit":null,"description":"CustomEvent is now stable."}],"type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"default":null,"description":"Returns custom data passed when initializing.\n\nRead-only.","summary":"Read-only.","examples":[],"children":[]}]},{"kind":"class","id":"class-nodeeventtarget","name":"NodeEventTarget","title":"Class: `NodeEventTarget`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"The `NodeEventTarget` is a Node.js-specific extension to `EventTarget`\nthat emulates a subset of the `EventEmitter` API.","summary":"The `NodeEventTarget` is a Node.js-specific extension to `EventTarget` that emulates a subset of the `EventEmitter` API.","examples":[],"children":[{"kind":"method","id":"nodeeventtargetaddlistenertype-listener","name":"addListener","title":"`nodeEventTarget.addListener(type, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific extension to the `EventTarget` class that emulates the\nequivalent `EventEmitter` API. The only difference between `addListener()` and\n`addEventListener()` is that `addListener()` will return a reference to the\n`EventTarget`.","summary":"Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API. The only difference between `addListener()` and `addEventListener()` is that `addListener()` will return a reference to the `EventTarget`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetemittype-arg","name":"emit","title":"`nodeEventTarget.emit(type, arg)`","scope":"module","overloadOf":null,"stability":null,"added":["v15.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"arg","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if event listeners registered for the `type` exist,\notherwise `false`."}},"description":"Node.js-specific extension to the `EventTarget` class that dispatches the\n`arg` to the list of handlers for `type`.","summary":"Node.js-specific extension to the `EventTarget` class that dispatches the `arg` to the list of handlers for `type`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargeteventnames","name":"eventNames","title":"`nodeEventTarget.eventNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Node.js-specific extension to the `EventTarget` class that returns an array\nof event `type` names for which event listeners are registered.","summary":"Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetlistenercounttype","name":"listenerCount","title":"`nodeEventTarget.listenerCount(type)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":""}},"description":"Node.js-specific extension to the `EventTarget` class that returns the number\nof event listeners registered for the `type`.","summary":"Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetsetmaxlistenersn","name":"setMaxListeners","title":"`nodeEventTarget.setMaxListeners(n)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"n","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Node.js-specific extension to the `EventTarget` class that sets the number\nof max event listeners as `n`.","summary":"Node.js-specific extension to the `EventTarget` class that sets the number of max event listeners as `n`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetgetmaxlisteners","name":"getMaxListeners","title":"`nodeEventTarget.getMaxListeners()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":""}},"description":"Node.js-specific extension to the `EventTarget` class that returns the number\nof max event listeners.","summary":"Node.js-specific extension to the `EventTarget` class that returns the number of max event listeners.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetofftype-listener-options","name":"off","title":"`nodeEventTarget.off(type, listener[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"capture","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific alias for `eventTarget.removeEventListener()`.","summary":"Node.js-specific alias for `eventTarget.removeEventListener()`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetontype-listener","name":"on","title":"`nodeEventTarget.on(type, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific alias for `eventTarget.addEventListener()`.","summary":"Node.js-specific alias for `eventTarget.addEventListener()`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetoncetype-listener","name":"once","title":"`nodeEventTarget.once(type, listener)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific extension to the `EventTarget` class that adds a `once`\nlistener for the given event `type`. This is equivalent to calling `on`\nwith the `once` option set to `true`.","summary":"Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetremovealllistenerstype","name":"removeAllListeners","title":"`nodeEventTarget.removeAllListeners([type])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific extension to the `EventTarget` class. If `type` is specified,\nremoves all registered listeners for `type`, otherwise removes all registered\nlisteners.","summary":"Node.js-specific extension to the `EventTarget` class. If `type` is specified, removes all registered listeners for `type`, otherwise removes all registered listeners.","examples":[],"children":[]},{"kind":"method","id":"nodeeventtargetremovelistenertype-listener-options","name":"removeListener","title":"`nodeEventTarget.removeListener(type, listener[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"listener","type":{"text":"Function | EventListener","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"EventListener","href":"events.html#event-listener","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"capture","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"EventTarget","links":[{"name":"EventTarget","href":"events.html#class-eventtarget","start":0,"end":11}]},"description":"this"}},"description":"Node.js-specific extension to the `EventTarget` class that removes the\n`listener` for the given `type`. The only difference between `removeListener()`\nand `removeEventListener()` is that `removeListener()` will return a reference\nto the `EventTarget`.","summary":"Node.js-specific extension to the `EventTarget` class that removes the `listener` for the given `type`. The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.","examples":[],"children":[]}]}]}]}