• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{
2  "type": "module",
3  "source": "doc/api/events.md",
4  "modules": [
5    {
6      "textRaw": "Events",
7      "name": "Events",
8      "introduced_in": "v0.10.0",
9      "stability": 2,
10      "stabilityText": "Stable",
11      "type": "module",
12      "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v14.20.1/lib/events.js\">lib/events.js</a></p>\n<p>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 <code>Function</code> objects (\"listeners\") to be called.</p>\n<p>For instance: a <a href=\"net.html#net_class_net_server\"><code>net.Server</code></a> object emits an event each time a peer\nconnects to it; a <a href=\"fs.html#fs_class_fs_readstream\"><code>fs.ReadStream</code></a> emits an event when the file is opened;\na <a href=\"stream.html\">stream</a> emits an event whenever data is available to be read.</p>\n<p>All objects that emit events are instances of the <code>EventEmitter</code> class. These\nobjects expose an <code>eventEmitter.on()</code> 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.</p>\n<p>When the <code>EventEmitter</code> object emits an event, all of the functions attached\nto that specific event are called <em>synchronously</em>. Any values returned by the\ncalled listeners are <em>ignored</em> and discarded.</p>\n<p>The following example shows a simple <code>EventEmitter</code> instance with a single\nlistener. The <code>eventEmitter.on()</code> method is used to register listeners, while\nthe <code>eventEmitter.emit()</code> method is used to trigger the event.</p>\n<pre><code class=\"language-js\">const EventEmitter = require('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</code></pre>",
13      "modules": [
14        {
15          "textRaw": "Passing arguments and `this` to listeners",
16          "name": "passing_arguments_and_`this`_to_listeners",
17          "desc": "<p>The <code>eventEmitter.emit()</code> 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 <code>this</code> keyword\nis intentionally set to reference the <code>EventEmitter</code> instance to which the\nlistener is attached.</p>\n<pre><code class=\"language-js\">const myEmitter = new MyEmitter();\nmyEmitter.on('event', function(a, b) {\n  console.log(a, b, this, this === myEmitter);\n  // Prints:\n  //   a b MyEmitter {\n  //     domain: null,\n  //     _events: { event: [Function] },\n  //     _eventsCount: 1,\n  //     _maxListeners: undefined } true\n});\nmyEmitter.emit('event', 'a', 'b');\n</code></pre>\n<p>It is possible to use ES6 Arrow Functions as listeners, however, when doing so,\nthe <code>this</code> keyword will no longer reference the <code>EventEmitter</code> instance:</p>\n<pre><code class=\"language-js\">const 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</code></pre>",
18          "type": "module",
19          "displayName": "Passing arguments and `this` to listeners"
20        },
21        {
22          "textRaw": "Asynchronous vs. synchronous",
23          "name": "asynchronous_vs._synchronous",
24          "desc": "<p>The <code>EventEmitter</code> 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 <code>setImmediate()</code> or <code>process.nextTick()</code> methods:</p>\n<pre><code class=\"language-js\">const myEmitter = new MyEmitter();\nmyEmitter.on('event', (a, b) => {\n  setImmediate(() => {\n    console.log('this happens asynchronously');\n  });\n});\nmyEmitter.emit('event', 'a', 'b');\n</code></pre>",
25          "type": "module",
26          "displayName": "Asynchronous vs. synchronous"
27        },
28        {
29          "textRaw": "Handling events only once",
30          "name": "handling_events_only_once",
31          "desc": "<p>When a listener is registered using the <code>eventEmitter.on()</code> method, that\nlistener is invoked <em>every time</em> the named event is emitted.</p>\n<pre><code class=\"language-js\">const 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</code></pre>\n<p>Using the <code>eventEmitter.once()</code> 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 <em>then</em> called.</p>\n<pre><code class=\"language-js\">const 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</code></pre>",
32          "type": "module",
33          "displayName": "Handling events only once"
34        },
35        {
36          "textRaw": "Error events",
37          "name": "error_events",
38          "desc": "<p>When an error occurs within an <code>EventEmitter</code> instance, the typical action is\nfor an <code>'error'</code> event to be emitted. These are treated as special cases\nwithin Node.js.</p>\n<p>If an <code>EventEmitter</code> does <em>not</em> have at least one listener registered for the\n<code>'error'</code> event, and an <code>'error'</code> event is emitted, the error is thrown, a\nstack trace is printed, and the Node.js process exits.</p>\n<pre><code class=\"language-js\">const myEmitter = new MyEmitter();\nmyEmitter.emit('error', new Error('whoops!'));\n// Throws and crashes Node.js\n</code></pre>\n<p>To guard against crashing the Node.js process the <a href=\"domain.html\"><code>domain</code></a> module can be\nused. (Note, however, that the <code>domain</code> module is deprecated.)</p>\n<p>As a best practice, listeners should always be added for the <code>'error'</code> events.</p>\n<pre><code class=\"language-js\">const 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</code></pre>\n<p>It is possible to monitor <code>'error'</code> events without consuming the emitted error\nby installing a listener using the symbol <code>events.errorMonitor</code>.</p>\n<pre><code class=\"language-js\">const { EventEmitter, errorMonitor } = require('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</code></pre>",
39          "type": "module",
40          "displayName": "Error events"
41        },
42        {
43          "textRaw": "Capture rejections of promises",
44          "name": "capture_rejections_of_promises",
45          "stability": 1,
46          "stabilityText": "captureRejections is experimental.",
47          "desc": "<p>Using <code>async</code> functions with event handlers is problematic, because it\ncan lead to an unhandled rejection in case of a thrown exception:</p>\n<pre><code class=\"language-js\">const ee = new EventEmitter();\nee.on('something', async (value) => {\n  throw new Error('kaboom');\n});\n</code></pre>\n<p>The <code>captureRejections</code> option in the <code>EventEmitter</code> constructor or the global\nsetting change this behavior, installing a <code>.then(undefined, handler)</code>\nhandler on the <code>Promise</code>. This handler routes the exception\nasynchronously to the <a href=\"#events_emitter_symbol_for_nodejs_rejection_err_eventname_args\"><code>Symbol.for('nodejs.rejection')</code></a> method\nif there is one, or to <a href=\"#events_error_events\"><code>'error'</code></a> event handler if there is none.</p>\n<pre><code class=\"language-js\">const 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</code></pre>\n<p>Setting <code>events.captureRejections = true</code> will change the default for all\nnew instances of <code>EventEmitter</code>.</p>\n<pre><code class=\"language-js\">const events = require('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</code></pre>\n<p>The <code>'error'</code> events that are generated by the <code>captureRejections</code> behavior\ndo not have a catch handler to avoid infinite error loops: the\nrecommendation is to <strong>not use <code>async</code> functions as <code>'error'</code> event handlers</strong>.</p>",
48          "type": "module",
49          "displayName": "Capture rejections of promises"
50        },
51        {
52          "textRaw": "`EventTarget` and `Event` API",
53          "name": "`eventtarget`_and_`event`_api",
54          "meta": {
55            "added": [
56              "v14.5.0"
57            ],
58            "changes": []
59          },
60          "stability": 1,
61          "stabilityText": "Experimental",
62          "desc": "<p>The <code>EventTarget</code> and <code>Event</code> objects are a Node.js-specific implementation\nof the <a href=\"https://dom.spec.whatwg.org/#eventtarget\"><code>EventTarget</code> Web API</a> that are exposed by some Node.js core APIs.\nNeither the <code>EventTarget</code> nor <code>Event</code> classes are available for end\nuser code to create.</p>\n<pre><code class=\"language-js\">const target = getEventTargetSomehow();\n\ntarget.addEventListener('foo', (event) => {\n  console.log('foo event happened!');\n});\n</code></pre>",
63          "modules": [
64            {
65              "textRaw": "Node.js `EventTarget` vs. DOM `EventTarget`",
66              "name": "node.js_`eventtarget`_vs._dom_`eventtarget`",
67              "desc": "<p>There are two key differences between the Node.js <code>EventTarget</code> and the\n<a href=\"https://dom.spec.whatwg.org/#eventtarget\"><code>EventTarget</code> Web API</a>:</p>\n<ol>\n<li>Whereas DOM <code>EventTarget</code> instances <em>may</em> be hierarchical, there is no\nconcept of hierarchy and event propagation in Node.js. That is, an event\ndispatched to an <code>EventTarget</code> does not propagate through a hierarchy of\nnested target objects that may each have their own set of handlers for the\nevent.</li>\n<li>In the Node.js <code>EventTarget</code>, if an event listener is an async function\nor returns a <code>Promise</code>, and the returned <code>Promise</code> rejects, the rejection\nis automatically captured and handled the same way as a listener that\nthrows synchronously (see <a href=\"#events_eventtarget_error_handling\"><code>EventTarget</code> error handling</a> for details).</li>\n</ol>",
68              "type": "module",
69              "displayName": "Node.js `EventTarget` vs. DOM `EventTarget`"
70            },
71            {
72              "textRaw": "`NodeEventTarget` vs. `EventEmitter`",
73              "name": "`nodeeventtarget`_vs._`eventemitter`",
74              "desc": "<p>The <code>NodeEventTarget</code> object implements a modified subset of the\n<code>EventEmitter</code> API that allows it to closely <em>emulate</em> an <code>EventEmitter</code> in\ncertain situations. A <code>NodeEventTarget</code> is <em>not</em> an instance of <code>EventEmitter</code>\nand cannot be used in place of an <code>EventEmitter</code> in most cases.</p>\n<ol>\n<li>Unlike <code>EventEmitter</code>, any given <code>listener</code> can be registered at most once\nper event <code>type</code>. Attempts to register a <code>listener</code> multiple times are\nignored.</li>\n<li>The <code>NodeEventTarget</code> does not emulate the full <code>EventEmitter</code> API.\nSpecifically the <code>prependListener()</code>, <code>prependOnceListener()</code>,\n<code>rawListeners()</code>, <code>setMaxListeners()</code>, <code>getMaxListeners()</code>, and\n<code>errorMonitor</code> APIs are not emulated. The <code>'newListener'</code> and\n<code>'removeListener'</code> events will also not be emitted.</li>\n<li>The <code>NodeEventTarget</code> does not implement any special default behavior\nfor events with type <code>'error'</code>.</li>\n<li>The <code>NodeEventTarget</code> supports <code>EventListener</code> objects as well as\nfunctions as handlers for all event types.</li>\n</ol>",
75              "type": "module",
76              "displayName": "`NodeEventTarget` vs. `EventEmitter`"
77            },
78            {
79              "textRaw": "Event listener",
80              "name": "event_listener",
81              "desc": "<p>Event listeners registered for an event <code>type</code> may either be JavaScript\nfunctions or objects with a <code>handleEvent</code> property whose value is a function.</p>\n<p>In either case, the handler function is invoked with the <code>event</code> argument\npassed to the <code>eventTarget.dispatchEvent()</code> function.</p>\n<p>Async functions may be used as event listeners. If an async handler function\nrejects, the rejection is captured and handled as described in\n<a href=\"#events_eventtarget_error_handling\"><code>EventTarget</code> error handling</a>.</p>\n<p>An error thrown by one handler function does not prevent the other handlers\nfrom being invoked.</p>\n<p>The return value of a handler function is ignored.</p>\n<p>Handlers are always invoked in the order they were added.</p>\n<p>Handler functions may mutate the <code>event</code> object.</p>\n<pre><code class=\"language-js\">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 = getEventTargetSomehow();\n\ntarget.addEventListener('foo', handler1);\ntarget.addEventListener('foo', handler2);\ntarget.addEventListener('foo', handler3);\ntarget.addEventListener('foo', handler4, { once: true });\n</code></pre>",
82              "type": "module",
83              "displayName": "Event listener"
84            },
85            {
86              "textRaw": "`EventTarget` error handling",
87              "name": "`eventtarget`_error_handling",
88              "desc": "<p>When a registered event listener throws (or returns a Promise that rejects),\nby default the error is treated as an uncaught exception on\n<code>process.nextTick()</code>. This means uncaught exceptions in <code>EventTarget</code>s will\nterminate the Node.js process by default.</p>\n<p>Throwing within an event listener will <em>not</em> stop the other registered handlers\nfrom being invoked.</p>\n<p>The <code>EventTarget</code> does not implement any special default handling for <code>'error'</code>\ntype events like <code>EventEmitter</code>.</p>\n<p>Currently errors are first forwarded to the <code>process.on('error')</code> event\nbefore reaching <code>process.on('uncaughtException')</code>. This behavior is\ndeprecated and will change in a future release to align <code>EventTarget</code> with\nother Node.js APIs. Any code relying on the <code>process.on('error')</code> event should\nbe aligned with the new behavior.</p>",
89              "type": "module",
90              "displayName": "`EventTarget` error handling"
91            }
92          ],
93          "classes": [
94            {
95              "textRaw": "Class: `Event`",
96              "type": "class",
97              "name": "Event",
98              "meta": {
99                "added": [
100                  "v14.5.0"
101                ],
102                "changes": []
103              },
104              "desc": "<p>The <code>Event</code> object is an adaptation of the <a href=\"https://dom.spec.whatwg.org/#event\"><code>Event</code> Web API</a>. Instances\nare created internally by Node.js.</p>",
105              "properties": [
106                {
107                  "textRaw": "`bubbles` Type: {boolean} Always returns `false`.",
108                  "type": "boolean",
109                  "name": "Type",
110                  "meta": {
111                    "added": [
112                      "v14.5.0"
113                    ],
114                    "changes": []
115                  },
116                  "desc": "<p>This is not used in Node.js and is provided purely for completeness.</p>",
117                  "shortDesc": "Always returns `false`."
118                },
119                {
120                  "textRaw": "`cancelable` Type: {boolean} True if the event was created with the `cancelable` option.",
121                  "type": "boolean",
122                  "name": "Type",
123                  "meta": {
124                    "added": [
125                      "v14.5.0"
126                    ],
127                    "changes": []
128                  },
129                  "desc": "True if the event was created with the `cancelable` option."
130                },
131                {
132                  "textRaw": "`composed` Type: {boolean} Always returns `false`.",
133                  "type": "boolean",
134                  "name": "Type",
135                  "meta": {
136                    "added": [
137                      "v14.5.0"
138                    ],
139                    "changes": []
140                  },
141                  "desc": "<p>This is not used in Node.js and is provided purely for completeness.</p>",
142                  "shortDesc": "Always returns `false`."
143                },
144                {
145                  "textRaw": "`currentTarget` Type: {EventTarget} The `EventTarget` dispatching the event.",
146                  "type": "EventTarget",
147                  "name": "Type",
148                  "meta": {
149                    "added": [
150                      "v14.5.0"
151                    ],
152                    "changes": []
153                  },
154                  "desc": "<p>Alias for <code>event.target</code>.</p>",
155                  "shortDesc": "The `EventTarget` dispatching the event."
156                },
157                {
158                  "textRaw": "`defaultPrevented` Type: {boolean}",
159                  "type": "boolean",
160                  "name": "Type",
161                  "meta": {
162                    "added": [
163                      "v14.5.0"
164                    ],
165                    "changes": []
166                  },
167                  "desc": "<p>Is <code>true</code> if <code>cancelable</code> is <code>true</code> and <code>event.preventDefault()</code> has been\ncalled.</p>"
168                },
169                {
170                  "textRaw": "`eventPhase` Type: {number} Returns `0` while an event is not being dispatched, `2` while it is being dispatched.",
171                  "type": "number",
172                  "name": "Type",
173                  "meta": {
174                    "added": [
175                      "v14.5.0"
176                    ],
177                    "changes": []
178                  },
179                  "desc": "<p>This is not used in Node.js and is provided purely for completeness.</p>",
180                  "shortDesc": "Returns `0` while an event is not being dispatched, `2` while it is being dispatched."
181                },
182                {
183                  "textRaw": "`isTrusted` Type: {boolean}",
184                  "type": "boolean",
185                  "name": "Type",
186                  "meta": {
187                    "added": [
188                      "v14.5.0"
189                    ],
190                    "changes": []
191                  },
192                  "desc": "<p>The <a href=\"globals.html#globals_class_abortsignal\" class=\"type\">&lt;AbortSignal&gt;</a> <code>\"abort\"</code> event is emitted with <code>isTrusted</code> set to <code>true</code>. The\nvalue is <code>false</code> in all other cases.</p>"
193                },
194                {
195                  "textRaw": "`returnValue` Type: {boolean} True if the event has not been canceled.",
196                  "type": "boolean",
197                  "name": "Type",
198                  "meta": {
199                    "added": [
200                      "v14.5.0"
201                    ],
202                    "changes": []
203                  },
204                  "desc": "<p>This is not used in Node.js and is provided purely for completeness.</p>",
205                  "shortDesc": "True if the event has not been canceled."
206                },
207                {
208                  "textRaw": "`srcElement` Type: {EventTarget} The `EventTarget` dispatching the event.",
209                  "type": "EventTarget",
210                  "name": "Type",
211                  "meta": {
212                    "added": [
213                      "v14.5.0"
214                    ],
215                    "changes": []
216                  },
217                  "desc": "<p>Alias for <code>event.target</code>.</p>",
218                  "shortDesc": "The `EventTarget` dispatching the event."
219                },
220                {
221                  "textRaw": "`target` Type: {EventTarget} The `EventTarget` dispatching the event.",
222                  "type": "EventTarget",
223                  "name": "Type",
224                  "meta": {
225                    "added": [
226                      "v14.5.0"
227                    ],
228                    "changes": []
229                  },
230                  "desc": "The `EventTarget` dispatching the event."
231                },
232                {
233                  "textRaw": "`timeStamp` Type: {number}",
234                  "type": "number",
235                  "name": "Type",
236                  "meta": {
237                    "added": [
238                      "v14.5.0"
239                    ],
240                    "changes": []
241                  },
242                  "desc": "<p>The millisecond timestamp when the <code>Event</code> object was created.</p>"
243                },
244                {
245                  "textRaw": "`type` Type: {string}",
246                  "type": "string",
247                  "name": "Type",
248                  "meta": {
249                    "added": [
250                      "v14.5.0"
251                    ],
252                    "changes": []
253                  },
254                  "desc": "<p>The event type identifier.</p>"
255                }
256              ],
257              "methods": [
258                {
259                  "textRaw": "`event.cancelBubble()`",
260                  "type": "method",
261                  "name": "cancelBubble",
262                  "meta": {
263                    "added": [
264                      "v14.5.0"
265                    ],
266                    "changes": []
267                  },
268                  "signatures": [
269                    {
270                      "params": []
271                    }
272                  ],
273                  "desc": "<p>Alias for <code>event.stopPropagation()</code>. This is not used in Node.js and is\nprovided purely for completeness.</p>"
274                },
275                {
276                  "textRaw": "`event.composedPath()`",
277                  "type": "method",
278                  "name": "composedPath",
279                  "meta": {
280                    "added": [
281                      "v14.5.0"
282                    ],
283                    "changes": []
284                  },
285                  "signatures": [
286                    {
287                      "params": []
288                    }
289                  ],
290                  "desc": "<p>Returns an array containing the current <code>EventTarget</code> 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.</p>"
291                },
292                {
293                  "textRaw": "`event.preventDefault()`",
294                  "type": "method",
295                  "name": "preventDefault",
296                  "meta": {
297                    "added": [
298                      "v14.5.0"
299                    ],
300                    "changes": []
301                  },
302                  "signatures": [
303                    {
304                      "params": []
305                    }
306                  ],
307                  "desc": "<p>Sets the <code>defaultPrevented</code> property to <code>true</code> if <code>cancelable</code> is <code>true</code>.</p>"
308                },
309                {
310                  "textRaw": "`event.stopImmediatePropagation()`",
311                  "type": "method",
312                  "name": "stopImmediatePropagation",
313                  "meta": {
314                    "added": [
315                      "v14.5.0"
316                    ],
317                    "changes": []
318                  },
319                  "signatures": [
320                    {
321                      "params": []
322                    }
323                  ],
324                  "desc": "<p>Stops the invocation of event listeners after the current one completes.</p>"
325                },
326                {
327                  "textRaw": "`event.stopPropagation()`",
328                  "type": "method",
329                  "name": "stopPropagation",
330                  "meta": {
331                    "added": [
332                      "v14.5.0"
333                    ],
334                    "changes": []
335                  },
336                  "signatures": [
337                    {
338                      "params": []
339                    }
340                  ],
341                  "desc": "<p>This is not used in Node.js and is provided purely for completeness.</p>"
342                }
343              ]
344            },
345            {
346              "textRaw": "Class: `EventTarget`",
347              "type": "class",
348              "name": "EventTarget",
349              "meta": {
350                "added": [
351                  "v14.5.0"
352                ],
353                "changes": []
354              },
355              "methods": [
356                {
357                  "textRaw": "`eventTarget.addEventListener(type, listener[, options])`",
358                  "type": "method",
359                  "name": "addEventListener",
360                  "meta": {
361                    "added": [
362                      "v14.5.0"
363                    ],
364                    "changes": []
365                  },
366                  "signatures": [
367                    {
368                      "params": [
369                        {
370                          "textRaw": "`type` {string}",
371                          "name": "type",
372                          "type": "string"
373                        },
374                        {
375                          "textRaw": "`listener` {Function|EventListener}",
376                          "name": "listener",
377                          "type": "Function|EventListener"
378                        },
379                        {
380                          "textRaw": "`options` {Object}",
381                          "name": "options",
382                          "type": "Object",
383                          "options": [
384                            {
385                              "textRaw": "`once` {boolean} When `true`, the listener is automatically removed when it is first invoked. **Default:** `false`.",
386                              "name": "once",
387                              "type": "boolean",
388                              "default": "`false`",
389                              "desc": "When `true`, the listener is automatically removed when it is first invoked."
390                            },
391                            {
392                              "textRaw": "`passive` {boolean} When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. **Default:** `false`.",
393                              "name": "passive",
394                              "type": "boolean",
395                              "default": "`false`",
396                              "desc": "When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method."
397                            },
398                            {
399                              "textRaw": "`capture` {boolean} Not directly used by Node.js. Added for API completeness. **Default:** `false`.",
400                              "name": "capture",
401                              "type": "boolean",
402                              "default": "`false`",
403                              "desc": "Not directly used by Node.js. Added for API completeness."
404                            }
405                          ]
406                        }
407                      ]
408                    }
409                  ],
410                  "desc": "<p>Adds a new handler for the <code>type</code> event. Any given <code>listener</code> is added\nonly once per <code>type</code> and per <code>capture</code> option value.</p>\n<p>If the <code>once</code> option is <code>true</code>, the <code>listener</code> is removed after the\nnext time a <code>type</code> event is dispatched.</p>\n<p>The <code>capture</code> option is not used by Node.js in any functional way other than\ntracking registered event listeners per the <code>EventTarget</code> specification.\nSpecifically, the <code>capture</code> option is used as part of the key when registering\na <code>listener</code>. Any individual <code>listener</code> may be added once with\n<code>capture = false</code>, and once with <code>capture = true</code>.</p>\n<pre><code class=\"language-js\">function handler(event) {}\n\nconst target = getEventTargetSomehow();\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</code></pre>"
411                },
412                {
413                  "textRaw": "`eventTarget.dispatchEvent(event)`",
414                  "type": "method",
415                  "name": "dispatchEvent",
416                  "meta": {
417                    "added": [
418                      "v14.5.0"
419                    ],
420                    "changes": []
421                  },
422                  "signatures": [
423                    {
424                      "return": {
425                        "textRaw": "Returns: {boolean} `true` if either event’s `cancelable` attribute value is false or its `preventDefault()` method was not invoked, otherwise `false`.",
426                        "name": "return",
427                        "type": "boolean",
428                        "desc": "`true` if either event’s `cancelable` attribute value is false or its `preventDefault()` method was not invoked, otherwise `false`."
429                      },
430                      "params": [
431                        {
432                          "textRaw": "`event` {Event}",
433                          "name": "event",
434                          "type": "Event"
435                        }
436                      ]
437                    }
438                  ],
439                  "desc": "<p>Dispatches the <code>event</code> to the list of handlers for <code>event.type</code>.</p>\n<p>The registered event listeners is synchronously invoked in the order they\nwere registered.</p>"
440                },
441                {
442                  "textRaw": "`eventTarget.removeEventListener(type, listener)`",
443                  "type": "method",
444                  "name": "removeEventListener",
445                  "meta": {
446                    "added": [
447                      "v14.5.0"
448                    ],
449                    "changes": []
450                  },
451                  "signatures": [
452                    {
453                      "params": [
454                        {
455                          "textRaw": "`type` {string}",
456                          "name": "type",
457                          "type": "string"
458                        },
459                        {
460                          "textRaw": "`listener` {Function|EventListener}",
461                          "name": "listener",
462                          "type": "Function|EventListener"
463                        },
464                        {
465                          "textRaw": "`options` {Object}",
466                          "name": "options",
467                          "type": "Object",
468                          "options": [
469                            {
470                              "textRaw": "`capture` {boolean}",
471                              "name": "capture",
472                              "type": "boolean"
473                            }
474                          ]
475                        }
476                      ]
477                    }
478                  ],
479                  "desc": "<p>Removes the <code>listener</code> from the list of handlers for event <code>type</code>.</p>"
480                }
481              ]
482            },
483            {
484              "textRaw": "Class: `NodeEventTarget`",
485              "type": "class",
486              "name": "NodeEventTarget",
487              "meta": {
488                "added": [
489                  "v14.5.0"
490                ],
491                "changes": []
492              },
493              "desc": "<ul>\n<li>Extends: <a href=\"events.html#events_class_eventtarget\" class=\"type\">&lt;EventTarget&gt;</a></li>\n</ul>\n<p>The <code>NodeEventTarget</code> is a Node.js-specific extension to <code>EventTarget</code>\nthat emulates a subset of the <code>EventEmitter</code> API.</p>",
494              "methods": [
495                {
496                  "textRaw": "`nodeEventTarget.addListener(type, listener[, options])`",
497                  "type": "method",
498                  "name": "addListener",
499                  "meta": {
500                    "added": [
501                      "v14.5.0"
502                    ],
503                    "changes": []
504                  },
505                  "signatures": [
506                    {
507                      "return": {
508                        "textRaw": "Returns: {EventTarget} this",
509                        "name": "return",
510                        "type": "EventTarget",
511                        "desc": "this"
512                      },
513                      "params": [
514                        {
515                          "textRaw": "`type` {string}",
516                          "name": "type",
517                          "type": "string"
518                        },
519                        {
520                          "textRaw": "`listener` {Function|EventListener}",
521                          "name": "listener",
522                          "type": "Function|EventListener"
523                        },
524                        {
525                          "textRaw": "`options` {Object}",
526                          "name": "options",
527                          "type": "Object",
528                          "options": [
529                            {
530                              "textRaw": "`once` {boolean}",
531                              "name": "once",
532                              "type": "boolean"
533                            }
534                          ]
535                        }
536                      ]
537                    }
538                  ],
539                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class that emulates the\nequivalent <code>EventEmitter</code> API. The only difference between <code>addListener()</code> and\n<code>addEventListener()</code> is that <code>addListener()</code> will return a reference to the\n<code>EventTarget</code>.</p>"
540                },
541                {
542                  "textRaw": "`nodeEventTarget.eventNames()`",
543                  "type": "method",
544                  "name": "eventNames",
545                  "meta": {
546                    "added": [
547                      "v14.5.0"
548                    ],
549                    "changes": []
550                  },
551                  "signatures": [
552                    {
553                      "return": {
554                        "textRaw": "Returns: {string[]}",
555                        "name": "return",
556                        "type": "string[]"
557                      },
558                      "params": []
559                    }
560                  ],
561                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class that returns an array\nof event <code>type</code> names for which event listeners are registered.</p>"
562                },
563                {
564                  "textRaw": "`nodeEventTarget.listenerCount(type)`",
565                  "type": "method",
566                  "name": "listenerCount",
567                  "meta": {
568                    "added": [
569                      "v14.5.0"
570                    ],
571                    "changes": []
572                  },
573                  "signatures": [
574                    {
575                      "return": {
576                        "textRaw": "Returns: {number}",
577                        "name": "return",
578                        "type": "number"
579                      },
580                      "params": [
581                        {
582                          "textRaw": "`type` {string}",
583                          "name": "type",
584                          "type": "string"
585                        }
586                      ]
587                    }
588                  ],
589                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class that returns the number\nof event listeners registered for the <code>type</code>.</p>"
590                },
591                {
592                  "textRaw": "`nodeEventTarget.off(type, listener)`",
593                  "type": "method",
594                  "name": "off",
595                  "meta": {
596                    "added": [
597                      "v14.5.0"
598                    ],
599                    "changes": []
600                  },
601                  "signatures": [
602                    {
603                      "return": {
604                        "textRaw": "Returns: {EventTarget} this",
605                        "name": "return",
606                        "type": "EventTarget",
607                        "desc": "this"
608                      },
609                      "params": [
610                        {
611                          "textRaw": "`type` {string}",
612                          "name": "type",
613                          "type": "string"
614                        },
615                        {
616                          "textRaw": "`listener` {Function|EventListener}",
617                          "name": "listener",
618                          "type": "Function|EventListener"
619                        }
620                      ]
621                    }
622                  ],
623                  "desc": "<p>Node.js-specific alias for <code>eventTarget.removeListener()</code>.</p>"
624                },
625                {
626                  "textRaw": "`nodeEventTarget.on(type, listener[, options])`",
627                  "type": "method",
628                  "name": "on",
629                  "meta": {
630                    "added": [
631                      "v14.5.0"
632                    ],
633                    "changes": []
634                  },
635                  "signatures": [
636                    {
637                      "return": {
638                        "textRaw": "Returns: {EventTarget} this",
639                        "name": "return",
640                        "type": "EventTarget",
641                        "desc": "this"
642                      },
643                      "params": [
644                        {
645                          "textRaw": "`type` {string}",
646                          "name": "type",
647                          "type": "string"
648                        },
649                        {
650                          "textRaw": "`listener` {Function|EventListener}",
651                          "name": "listener",
652                          "type": "Function|EventListener"
653                        },
654                        {
655                          "textRaw": "`options` {Object}",
656                          "name": "options",
657                          "type": "Object",
658                          "options": [
659                            {
660                              "textRaw": "`once` {boolean}",
661                              "name": "once",
662                              "type": "boolean"
663                            }
664                          ]
665                        }
666                      ]
667                    }
668                  ],
669                  "desc": "<p>Node.js-specific alias for <code>eventTarget.addListener()</code>.</p>"
670                },
671                {
672                  "textRaw": "`nodeEventTarget.once(type, listener[, options])`",
673                  "type": "method",
674                  "name": "once",
675                  "meta": {
676                    "added": [
677                      "v14.5.0"
678                    ],
679                    "changes": []
680                  },
681                  "signatures": [
682                    {
683                      "return": {
684                        "textRaw": "Returns: {EventTarget} this",
685                        "name": "return",
686                        "type": "EventTarget",
687                        "desc": "this"
688                      },
689                      "params": [
690                        {
691                          "textRaw": "`type` {string}",
692                          "name": "type",
693                          "type": "string"
694                        },
695                        {
696                          "textRaw": "`listener` {Function|EventListener}",
697                          "name": "listener",
698                          "type": "Function|EventListener"
699                        },
700                        {
701                          "textRaw": "`options` {Object}",
702                          "name": "options",
703                          "type": "Object"
704                        }
705                      ]
706                    }
707                  ],
708                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class that adds a <code>once</code>\nlistener for the given event <code>type</code>. This is equivalent to calling <code>on</code>\nwith the <code>once</code> option set to <code>true</code>.</p>"
709                },
710                {
711                  "textRaw": "`nodeEventTarget.removeAllListeners([type])`",
712                  "type": "method",
713                  "name": "removeAllListeners",
714                  "meta": {
715                    "added": [
716                      "v14.5.0"
717                    ],
718                    "changes": []
719                  },
720                  "signatures": [
721                    {
722                      "return": {
723                        "textRaw": "Returns: {EventTarget} this",
724                        "name": "return",
725                        "type": "EventTarget",
726                        "desc": "this"
727                      },
728                      "params": [
729                        {
730                          "textRaw": "`type` {string}",
731                          "name": "type",
732                          "type": "string"
733                        }
734                      ]
735                    }
736                  ],
737                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class. If <code>type</code> is specified,\nremoves all registered listeners for <code>type</code>, otherwise removes all registered\nlisteners.</p>"
738                },
739                {
740                  "textRaw": "`nodeEventTarget.removeListener(type, listener)`",
741                  "type": "method",
742                  "name": "removeListener",
743                  "meta": {
744                    "added": [
745                      "v14.5.0"
746                    ],
747                    "changes": []
748                  },
749                  "signatures": [
750                    {
751                      "return": {
752                        "textRaw": "Returns: {EventTarget} this",
753                        "name": "return",
754                        "type": "EventTarget",
755                        "desc": "this"
756                      },
757                      "params": [
758                        {
759                          "textRaw": "`type` {string}",
760                          "name": "type",
761                          "type": "string"
762                        },
763                        {
764                          "textRaw": "`listener` {Function|EventListener}",
765                          "name": "listener",
766                          "type": "Function|EventListener"
767                        }
768                      ]
769                    }
770                  ],
771                  "desc": "<p>Node.js-specific extension to the <code>EventTarget</code> class that removes the\n<code>listener</code> for the given <code>type</code>. The only difference between <code>removeListener()</code>\nand <code>removeEventListener()</code> is that <code>removeListener()</code> will return a reference\nto the <code>EventTarget</code>.</p>"
772                }
773              ]
774            }
775          ],
776          "type": "module",
777          "displayName": "`EventTarget` and `Event` API"
778        }
779      ],
780      "classes": [
781        {
782          "textRaw": "Class: `EventEmitter`",
783          "type": "class",
784          "name": "EventEmitter",
785          "meta": {
786            "added": [
787              "v0.1.26"
788            ],
789            "changes": [
790              {
791                "version": [
792                  "v13.4.0",
793                  "v12.16.0"
794                ],
795                "pr-url": "https://github.com/nodejs/node/pull/27867",
796                "description": "Added captureRejections option."
797              }
798            ]
799          },
800          "desc": "<p>The <code>EventEmitter</code> class is defined and exposed by the <code>events</code> module:</p>\n<pre><code class=\"language-js\">const EventEmitter = require('events');\n</code></pre>\n<p>All <code>EventEmitter</code>s emit the event <code>'newListener'</code> when new listeners are\nadded and <code>'removeListener'</code> when existing listeners are removed.</p>\n<p>It supports the following option:</p>\n<ul>\n<li><code>captureRejections</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> It enables\n<a href=\"#events_capture_rejections_of_promises\">automatic capturing of promise rejection</a>.\n<strong>Default:</strong> <code>false</code>.</li>\n</ul>",
801          "events": [
802            {
803              "textRaw": "Event: `'newListener'`",
804              "type": "event",
805              "name": "newListener",
806              "meta": {
807                "added": [
808                  "v0.1.26"
809                ],
810                "changes": []
811              },
812              "params": [
813                {
814                  "textRaw": "`eventName` {string|symbol} The name of the event being listened for",
815                  "name": "eventName",
816                  "type": "string|symbol",
817                  "desc": "The name of the event being listened for"
818                },
819                {
820                  "textRaw": "`listener` {Function} The event handler function",
821                  "name": "listener",
822                  "type": "Function",
823                  "desc": "The event handler function"
824                }
825              ],
826              "desc": "<p>The <code>EventEmitter</code> instance will emit its own <code>'newListener'</code> event <em>before</em>\na listener is added to its internal array of listeners.</p>\n<p>Listeners registered for the <code>'newListener'</code> event are passed the event\nname and a reference to the listener being added.</p>\n<p>The fact that the event is triggered before adding the listener has a subtle\nbut important side effect: any <em>additional</em> listeners registered to the same\n<code>name</code> <em>within</em> the <code>'newListener'</code> callback are inserted <em>before</em> the\nlistener that is in the process of being added.</p>\n<pre><code class=\"language-js\">class 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</code></pre>"
827            },
828            {
829              "textRaw": "Event: `'removeListener'`",
830              "type": "event",
831              "name": "removeListener",
832              "meta": {
833                "added": [
834                  "v0.9.3"
835                ],
836                "changes": [
837                  {
838                    "version": [
839                      "v6.1.0",
840                      "v4.7.0"
841                    ],
842                    "pr-url": "https://github.com/nodejs/node/pull/6394",
843                    "description": "For listeners attached using `.once()`, the `listener` argument now yields the original listener function."
844                  }
845                ]
846              },
847              "params": [
848                {
849                  "textRaw": "`eventName` {string|symbol} The event name",
850                  "name": "eventName",
851                  "type": "string|symbol",
852                  "desc": "The event name"
853                },
854                {
855                  "textRaw": "`listener` {Function} The event handler function",
856                  "name": "listener",
857                  "type": "Function",
858                  "desc": "The event handler function"
859                }
860              ],
861              "desc": "<p>The <code>'removeListener'</code> event is emitted <em>after</em> the <code>listener</code> is removed.</p>"
862            }
863          ],
864          "methods": [
865            {
866              "textRaw": "`emitter.addListener(eventName, listener)`",
867              "type": "method",
868              "name": "addListener",
869              "meta": {
870                "added": [
871                  "v0.1.26"
872                ],
873                "changes": []
874              },
875              "signatures": [
876                {
877                  "params": [
878                    {
879                      "textRaw": "`eventName` {string|symbol}",
880                      "name": "eventName",
881                      "type": "string|symbol"
882                    },
883                    {
884                      "textRaw": "`listener` {Function}",
885                      "name": "listener",
886                      "type": "Function"
887                    }
888                  ]
889                }
890              ],
891              "desc": "<p>Alias for <code>emitter.on(eventName, listener)</code>.</p>"
892            },
893            {
894              "textRaw": "`emitter.emit(eventName[, ...args])`",
895              "type": "method",
896              "name": "emit",
897              "meta": {
898                "added": [
899                  "v0.1.26"
900                ],
901                "changes": []
902              },
903              "signatures": [
904                {
905                  "return": {
906                    "textRaw": "Returns: {boolean}",
907                    "name": "return",
908                    "type": "boolean"
909                  },
910                  "params": [
911                    {
912                      "textRaw": "`eventName` {string|symbol}",
913                      "name": "eventName",
914                      "type": "string|symbol"
915                    },
916                    {
917                      "textRaw": "`...args` {any}",
918                      "name": "...args",
919                      "type": "any"
920                    }
921                  ]
922                }
923              ],
924              "desc": "<p>Synchronously calls each of the listeners registered for the event named\n<code>eventName</code>, in the order they were registered, passing the supplied arguments\nto each.</p>\n<p>Returns <code>true</code> if the event had listeners, <code>false</code> otherwise.</p>\n<pre><code class=\"language-js\">const EventEmitter = require('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</code></pre>"
925            },
926            {
927              "textRaw": "`emitter.eventNames()`",
928              "type": "method",
929              "name": "eventNames",
930              "meta": {
931                "added": [
932                  "v6.0.0"
933                ],
934                "changes": []
935              },
936              "signatures": [
937                {
938                  "return": {
939                    "textRaw": "Returns: {Array}",
940                    "name": "return",
941                    "type": "Array"
942                  },
943                  "params": []
944                }
945              ],
946              "desc": "<p>Returns an array listing the events for which the emitter has registered\nlisteners. The values in the array are strings or <code>Symbol</code>s.</p>\n<pre><code class=\"language-js\">const EventEmitter = require('events');\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</code></pre>"
947            },
948            {
949              "textRaw": "`emitter.getMaxListeners()`",
950              "type": "method",
951              "name": "getMaxListeners",
952              "meta": {
953                "added": [
954                  "v1.0.0"
955                ],
956                "changes": []
957              },
958              "signatures": [
959                {
960                  "return": {
961                    "textRaw": "Returns: {integer}",
962                    "name": "return",
963                    "type": "integer"
964                  },
965                  "params": []
966                }
967              ],
968              "desc": "<p>Returns the current max listener value for the <code>EventEmitter</code> which is either\nset by <a href=\"#events_emitter_setmaxlisteners_n\"><code>emitter.setMaxListeners(n)</code></a> or defaults to\n<a href=\"#events_events_defaultmaxlisteners\"><code>events.defaultMaxListeners</code></a>.</p>"
969            },
970            {
971              "textRaw": "`emitter.listenerCount(eventName)`",
972              "type": "method",
973              "name": "listenerCount",
974              "meta": {
975                "added": [
976                  "v3.2.0"
977                ],
978                "changes": []
979              },
980              "signatures": [
981                {
982                  "return": {
983                    "textRaw": "Returns: {integer}",
984                    "name": "return",
985                    "type": "integer"
986                  },
987                  "params": [
988                    {
989                      "textRaw": "`eventName` {string|symbol} The name of the event being listened for",
990                      "name": "eventName",
991                      "type": "string|symbol",
992                      "desc": "The name of the event being listened for"
993                    }
994                  ]
995                }
996              ],
997              "desc": "<p>Returns the number of listeners listening to the event named <code>eventName</code>.</p>"
998            },
999            {
1000              "textRaw": "`emitter.listeners(eventName)`",
1001              "type": "method",
1002              "name": "listeners",
1003              "meta": {
1004                "added": [
1005                  "v0.1.26"
1006                ],
1007                "changes": [
1008                  {
1009                    "version": "v7.0.0",
1010                    "pr-url": "https://github.com/nodejs/node/pull/6881",
1011                    "description": "For listeners attached using `.once()` this returns the original listeners instead of wrapper functions now."
1012                  }
1013                ]
1014              },
1015              "signatures": [
1016                {
1017                  "return": {
1018                    "textRaw": "Returns: {Function[]}",
1019                    "name": "return",
1020                    "type": "Function[]"
1021                  },
1022                  "params": [
1023                    {
1024                      "textRaw": "`eventName` {string|symbol}",
1025                      "name": "eventName",
1026                      "type": "string|symbol"
1027                    }
1028                  ]
1029                }
1030              ],
1031              "desc": "<p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>\n<pre><code class=\"language-js\">server.on('connection', (stream) => {\n  console.log('someone connected!');\n});\nconsole.log(util.inspect(server.listeners('connection')));\n// Prints: [ [Function] ]\n</code></pre>"
1032            },
1033            {
1034              "textRaw": "`emitter.off(eventName, listener)`",
1035              "type": "method",
1036              "name": "off",
1037              "meta": {
1038                "added": [
1039                  "v10.0.0"
1040                ],
1041                "changes": []
1042              },
1043              "signatures": [
1044                {
1045                  "return": {
1046                    "textRaw": "Returns: {EventEmitter}",
1047                    "name": "return",
1048                    "type": "EventEmitter"
1049                  },
1050                  "params": [
1051                    {
1052                      "textRaw": "`eventName` {string|symbol}",
1053                      "name": "eventName",
1054                      "type": "string|symbol"
1055                    },
1056                    {
1057                      "textRaw": "`listener` {Function}",
1058                      "name": "listener",
1059                      "type": "Function"
1060                    }
1061                  ]
1062                }
1063              ],
1064              "desc": "<p>Alias for <a href=\"#events_emitter_removelistener_eventname_listener\"><code>emitter.removeListener()</code></a>.</p>"
1065            },
1066            {
1067              "textRaw": "`emitter.on(eventName, listener)`",
1068              "type": "method",
1069              "name": "on",
1070              "meta": {
1071                "added": [
1072                  "v0.1.101"
1073                ],
1074                "changes": []
1075              },
1076              "signatures": [
1077                {
1078                  "return": {
1079                    "textRaw": "Returns: {EventEmitter}",
1080                    "name": "return",
1081                    "type": "EventEmitter"
1082                  },
1083                  "params": [
1084                    {
1085                      "textRaw": "`eventName` {string|symbol} The name of the event.",
1086                      "name": "eventName",
1087                      "type": "string|symbol",
1088                      "desc": "The name of the event."
1089                    },
1090                    {
1091                      "textRaw": "`listener` {Function} The callback function",
1092                      "name": "listener",
1093                      "type": "Function",
1094                      "desc": "The callback function"
1095                    }
1096                  ]
1097                }
1098              ],
1099              "desc": "<p>Adds the <code>listener</code> function to the end of the listeners array for the\nevent named <code>eventName</code>. No checks are made to see if the <code>listener</code> has\nalready been added. Multiple calls passing the same combination of <code>eventName</code>\nand <code>listener</code> will result in the <code>listener</code> being added, and called, multiple\ntimes.</p>\n<pre><code class=\"language-js\">server.on('connection', (stream) => {\n  console.log('someone connected!');\n});\n</code></pre>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>\n<p>By default, event listeners are invoked in the order they are added. The\n<code>emitter.prependListener()</code> method can be used as an alternative to add the\nevent listener to the beginning of the listeners array.</p>\n<pre><code class=\"language-js\">const 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</code></pre>"
1100            },
1101            {
1102              "textRaw": "`emitter.once(eventName, listener)`",
1103              "type": "method",
1104              "name": "once",
1105              "meta": {
1106                "added": [
1107                  "v0.3.0"
1108                ],
1109                "changes": []
1110              },
1111              "signatures": [
1112                {
1113                  "return": {
1114                    "textRaw": "Returns: {EventEmitter}",
1115                    "name": "return",
1116                    "type": "EventEmitter"
1117                  },
1118                  "params": [
1119                    {
1120                      "textRaw": "`eventName` {string|symbol} The name of the event.",
1121                      "name": "eventName",
1122                      "type": "string|symbol",
1123                      "desc": "The name of the event."
1124                    },
1125                    {
1126                      "textRaw": "`listener` {Function} The callback function",
1127                      "name": "listener",
1128                      "type": "Function",
1129                      "desc": "The callback function"
1130                    }
1131                  ]
1132                }
1133              ],
1134              "desc": "<p>Adds a <strong>one-time</strong> <code>listener</code> function for the event named <code>eventName</code>. The\nnext time <code>eventName</code> is triggered, this listener is removed and then invoked.</p>\n<pre><code class=\"language-js\">server.once('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});\n</code></pre>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>\n<p>By default, event listeners are invoked in the order they are added. The\n<code>emitter.prependOnceListener()</code> method can be used as an alternative to add the\nevent listener to the beginning of the listeners array.</p>\n<pre><code class=\"language-js\">const 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</code></pre>"
1135            },
1136            {
1137              "textRaw": "`emitter.prependListener(eventName, listener)`",
1138              "type": "method",
1139              "name": "prependListener",
1140              "meta": {
1141                "added": [
1142                  "v6.0.0"
1143                ],
1144                "changes": []
1145              },
1146              "signatures": [
1147                {
1148                  "return": {
1149                    "textRaw": "Returns: {EventEmitter}",
1150                    "name": "return",
1151                    "type": "EventEmitter"
1152                  },
1153                  "params": [
1154                    {
1155                      "textRaw": "`eventName` {string|symbol} The name of the event.",
1156                      "name": "eventName",
1157                      "type": "string|symbol",
1158                      "desc": "The name of the event."
1159                    },
1160                    {
1161                      "textRaw": "`listener` {Function} The callback function",
1162                      "name": "listener",
1163                      "type": "Function",
1164                      "desc": "The callback function"
1165                    }
1166                  ]
1167                }
1168              ],
1169              "desc": "<p>Adds the <code>listener</code> function to the <em>beginning</em> of the listeners array for the\nevent named <code>eventName</code>. No checks are made to see if the <code>listener</code> has\nalready been added. Multiple calls passing the same combination of <code>eventName</code>\nand <code>listener</code> will result in the <code>listener</code> being added, and called, multiple\ntimes.</p>\n<pre><code class=\"language-js\">server.prependListener('connection', (stream) => {\n  console.log('someone connected!');\n});\n</code></pre>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>"
1170            },
1171            {
1172              "textRaw": "`emitter.prependOnceListener(eventName, listener)`",
1173              "type": "method",
1174              "name": "prependOnceListener",
1175              "meta": {
1176                "added": [
1177                  "v6.0.0"
1178                ],
1179                "changes": []
1180              },
1181              "signatures": [
1182                {
1183                  "return": {
1184                    "textRaw": "Returns: {EventEmitter}",
1185                    "name": "return",
1186                    "type": "EventEmitter"
1187                  },
1188                  "params": [
1189                    {
1190                      "textRaw": "`eventName` {string|symbol} The name of the event.",
1191                      "name": "eventName",
1192                      "type": "string|symbol",
1193                      "desc": "The name of the event."
1194                    },
1195                    {
1196                      "textRaw": "`listener` {Function} The callback function",
1197                      "name": "listener",
1198                      "type": "Function",
1199                      "desc": "The callback function"
1200                    }
1201                  ]
1202                }
1203              ],
1204              "desc": "<p>Adds a <strong>one-time</strong> <code>listener</code> function for the event named <code>eventName</code> to the\n<em>beginning</em> of the listeners array. The next time <code>eventName</code> is triggered, this\nlistener is removed, and then invoked.</p>\n<pre><code class=\"language-js\">server.prependOnceListener('connection', (stream) => {\n  console.log('Ah, we have our first user!');\n});\n</code></pre>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>"
1205            },
1206            {
1207              "textRaw": "`emitter.removeAllListeners([eventName])`",
1208              "type": "method",
1209              "name": "removeAllListeners",
1210              "meta": {
1211                "added": [
1212                  "v0.1.26"
1213                ],
1214                "changes": []
1215              },
1216              "signatures": [
1217                {
1218                  "return": {
1219                    "textRaw": "Returns: {EventEmitter}",
1220                    "name": "return",
1221                    "type": "EventEmitter"
1222                  },
1223                  "params": [
1224                    {
1225                      "textRaw": "`eventName` {string|symbol}",
1226                      "name": "eventName",
1227                      "type": "string|symbol"
1228                    }
1229                  ]
1230                }
1231              ],
1232              "desc": "<p>Removes all listeners, or those of the specified <code>eventName</code>.</p>\n<p>It is bad practice to remove listeners added elsewhere in the code,\nparticularly when the <code>EventEmitter</code> instance was created by some other\ncomponent or module (e.g. sockets or file streams).</p>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>"
1233            },
1234            {
1235              "textRaw": "`emitter.removeListener(eventName, listener)`",
1236              "type": "method",
1237              "name": "removeListener",
1238              "meta": {
1239                "added": [
1240                  "v0.1.26"
1241                ],
1242                "changes": []
1243              },
1244              "signatures": [
1245                {
1246                  "return": {
1247                    "textRaw": "Returns: {EventEmitter}",
1248                    "name": "return",
1249                    "type": "EventEmitter"
1250                  },
1251                  "params": [
1252                    {
1253                      "textRaw": "`eventName` {string|symbol}",
1254                      "name": "eventName",
1255                      "type": "string|symbol"
1256                    },
1257                    {
1258                      "textRaw": "`listener` {Function}",
1259                      "name": "listener",
1260                      "type": "Function"
1261                    }
1262                  ]
1263                }
1264              ],
1265              "desc": "<p>Removes the specified <code>listener</code> from the listener array for the event named\n<code>eventName</code>.</p>\n<pre><code class=\"language-js\">const callback = (stream) => {\n  console.log('someone connected!');\n};\nserver.on('connection', callback);\n// ...\nserver.removeListener('connection', callback);\n</code></pre>\n<p><code>removeListener()</code> 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 <code>eventName</code>, then <code>removeListener()</code> must be\ncalled multiple times to remove each instance.</p>\n<p>Once an event is emitted, all listeners attached to it at the\ntime of emitting are called in order. This implies that any\n<code>removeListener()</code> or <code>removeAllListeners()</code> calls <em>after</em> emitting and\n<em>before</em> the last listener finishes execution will not remove them from\n<code>emit()</code> in progress. Subsequent events behave as expected.</p>\n<pre><code class=\"language-js\">const 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</code></pre>\n<p>Because listeners are managed using an internal array, calling this will\nchange the position indices of any listener registered <em>after</em> 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 <code>emitter.listeners()</code> method will need to be recreated.</p>\n<p>When a single function has been added as a handler multiple times for a single\nevent (as in the example below), <code>removeListener()</code> will remove the most\nrecently added instance. In the example the <code>once('ping')</code>\nlistener is removed:</p>\n<pre><code class=\"language-js\">const 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</code></pre>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>"
1266            },
1267            {
1268              "textRaw": "`emitter.setMaxListeners(n)`",
1269              "type": "method",
1270              "name": "setMaxListeners",
1271              "meta": {
1272                "added": [
1273                  "v0.3.5"
1274                ],
1275                "changes": []
1276              },
1277              "signatures": [
1278                {
1279                  "return": {
1280                    "textRaw": "Returns: {EventEmitter}",
1281                    "name": "return",
1282                    "type": "EventEmitter"
1283                  },
1284                  "params": [
1285                    {
1286                      "textRaw": "`n` {integer}",
1287                      "name": "n",
1288                      "type": "integer"
1289                    }
1290                  ]
1291                }
1292              ],
1293              "desc": "<p>By default <code>EventEmitter</code>s will print a warning if more than <code>10</code> listeners are\nadded for a particular event. This is a useful default that helps finding\nmemory leaks. The <code>emitter.setMaxListeners()</code> method allows the limit to be\nmodified for this specific <code>EventEmitter</code> instance. The value can be set to\n<code>Infinity</code> (or <code>0</code>) to indicate an unlimited number of listeners.</p>\n<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>"
1294            },
1295            {
1296              "textRaw": "`emitter.rawListeners(eventName)`",
1297              "type": "method",
1298              "name": "rawListeners",
1299              "meta": {
1300                "added": [
1301                  "v9.4.0"
1302                ],
1303                "changes": []
1304              },
1305              "signatures": [
1306                {
1307                  "return": {
1308                    "textRaw": "Returns: {Function[]}",
1309                    "name": "return",
1310                    "type": "Function[]"
1311                  },
1312                  "params": [
1313                    {
1314                      "textRaw": "`eventName` {string|symbol}",
1315                      "name": "eventName",
1316                      "type": "string|symbol"
1317                    }
1318                  ]
1319                }
1320              ],
1321              "desc": "<p>Returns a copy of the array of listeners for the event named <code>eventName</code>,\nincluding any wrappers (such as those created by <code>.once()</code>).</p>\n<pre><code class=\"language-js\">const 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</code></pre>"
1322            }
1323          ],
1324          "modules": [
1325            {
1326              "textRaw": "`emitter[Symbol.for('nodejs.rejection')](err, eventName[, ...args])`",
1327              "name": "`emitter[symbol.for('nodejs.rejection')](err,_eventname[,_...args])`",
1328              "meta": {
1329                "added": [
1330                  "v13.4.0",
1331                  "v12.16.0"
1332                ],
1333                "changes": []
1334              },
1335              "stability": 1,
1336              "stabilityText": "captureRejections is experimental.",
1337              "desc": "<ul>\n<li><code>err</code> Error</li>\n<li><code>eventName</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type\" class=\"type\">&lt;symbol&gt;</a></li>\n<li><code>...args</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a></li>\n</ul>\n<p>The <code>Symbol.for('nodejs.rejection')</code> method is called in case a\npromise rejection happens when emitting an event and\n<a href=\"#events_capture_rejections_of_promises\"><code>captureRejections</code></a> is enabled on the emitter.\nIt is possible to use <a href=\"#events_events_capturerejectionsymbol\"><code>events.captureRejectionSymbol</code></a> in\nplace of <code>Symbol.for('nodejs.rejection')</code>.</p>\n<pre><code class=\"language-js\">const { EventEmitter, captureRejectionSymbol } = require('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</code></pre>",
1338              "type": "module",
1339              "displayName": "`emitter[Symbol.for('nodejs.rejection')](err, eventName[, ...args])`"
1340            }
1341          ]
1342        }
1343      ],
1344      "properties": [
1345        {
1346          "textRaw": "`events.defaultMaxListeners`",
1347          "name": "defaultMaxListeners",
1348          "meta": {
1349            "added": [
1350              "v0.11.2"
1351            ],
1352            "changes": []
1353          },
1354          "desc": "<p>By default, a maximum of <code>10</code> listeners can be registered for any single\nevent. This limit can be changed for individual <code>EventEmitter</code> instances\nusing the <a href=\"#events_emitter_setmaxlisteners_n\"><code>emitter.setMaxListeners(n)</code></a> method. To change the default\nfor <em>all</em> <code>EventEmitter</code> instances, the <code>events.defaultMaxListeners</code>\nproperty can be used. If this value is not a positive number, a <code>RangeError</code>\nis thrown.</p>\n<p>Take caution when setting the <code>events.defaultMaxListeners</code> because the\nchange affects <em>all</em> <code>EventEmitter</code> instances, including those created before\nthe change is made. However, calling <a href=\"#events_emitter_setmaxlisteners_n\"><code>emitter.setMaxListeners(n)</code></a> still has\nprecedence over <code>events.defaultMaxListeners</code>.</p>\n<p>This is not a hard limit. The <code>EventEmitter</code> 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<code>EventEmitter</code>, the <code>emitter.getMaxListeners()</code> and <code>emitter.setMaxListeners()</code>\nmethods can be used to temporarily avoid this warning:</p>\n<pre><code class=\"language-js\">emitter.setMaxListeners(emitter.getMaxListeners() + 1);\nemitter.once('event', () => {\n  // do stuff\n  emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));\n});\n</code></pre>\n<p>The <a href=\"cli.html#cli_trace_warnings\"><code>--trace-warnings</code></a> command-line flag can be used to display the\nstack trace for such warnings.</p>\n<p>The emitted warning can be inspected with <a href=\"process.html#process_event_warning\"><code>process.on('warning')</code></a> and will\nhave the additional <code>emitter</code>, <code>type</code> and <code>count</code> properties, referring to\nthe event emitter instance, the event’s name and the number of attached\nlisteners, respectively.\nIts <code>name</code> property is set to <code>'MaxListenersExceededWarning'</code>.</p>"
1355        },
1356        {
1357          "textRaw": "`events.errorMonitor`",
1358          "name": "errorMonitor",
1359          "meta": {
1360            "added": [
1361              "v13.6.0",
1362              "v12.17.0"
1363            ],
1364            "changes": []
1365          },
1366          "desc": "<p>This symbol shall be used to install a listener for only monitoring <code>'error'</code>\nevents. Listeners installed using this symbol are called before the regular\n<code>'error'</code> listeners are called.</p>\n<p>Installing a listener using this symbol does not change the behavior once an\n<code>'error'</code> event is emitted, therefore the process will still crash if no\nregular <code>'error'</code> listener is installed.</p>"
1367        },
1368        {
1369          "textRaw": "`events.captureRejections`",
1370          "name": "captureRejections",
1371          "meta": {
1372            "added": [
1373              "v13.4.0",
1374              "v12.16.0"
1375            ],
1376            "changes": []
1377          },
1378          "stability": 1,
1379          "stabilityText": "captureRejections is experimental.",
1380          "desc": "<p>Value: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a></p>\n<p>Change the default <code>captureRejections</code> option on all new <code>EventEmitter</code> objects.</p>"
1381        },
1382        {
1383          "textRaw": "`events.captureRejectionSymbol`",
1384          "name": "captureRejectionSymbol",
1385          "meta": {
1386            "added": [
1387              "v13.4.0",
1388              "v12.16.0"
1389            ],
1390            "changes": []
1391          },
1392          "stability": 1,
1393          "stabilityText": "captureRejections is experimental.",
1394          "desc": "<p>Value: <code>Symbol.for('nodejs.rejection')</code></p>\n<p>See how to write a custom <a href=\"#events_emitter_symbol_for_nodejs_rejection_err_eventname_args\">rejection handler</a>.</p>"
1395        }
1396      ],
1397      "methods": [
1398        {
1399          "textRaw": "`events.getEventListeners(emitterOrTarget, eventName)`",
1400          "type": "method",
1401          "name": "getEventListeners",
1402          "meta": {
1403            "added": [
1404              "v14.17.0"
1405            ],
1406            "changes": []
1407          },
1408          "signatures": [
1409            {
1410              "return": {
1411                "textRaw": "Returns: {Function[]}",
1412                "name": "return",
1413                "type": "Function[]"
1414              },
1415              "params": [
1416                {
1417                  "textRaw": "`emitterOrTarget` {EventEmitter|EventTarget}",
1418                  "name": "emitterOrTarget",
1419                  "type": "EventEmitter|EventTarget"
1420                },
1421                {
1422                  "textRaw": "`eventName` {string|symbol}",
1423                  "name": "eventName",
1424                  "type": "string|symbol"
1425                }
1426              ]
1427            }
1428          ],
1429          "desc": "<p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>\n<p>For <code>EventEmitter</code>s this behaves exactly the same as calling <code>.listeners</code> on\nthe emitter.</p>\n<p>For <code>EventTarget</code>s this is the only way to get the event listeners for the\nevent target. This is useful for debugging and diagnostic purposes.</p>\n<pre><code class=\"language-js\">const { getEventListeners, EventEmitter } = require('events');\n\n{\n  const ee = new EventEmitter();\n  const listener = () => console.log('Events are fun');\n  ee.on('foo', listener);\n  getEventListeners(ee, 'foo'); // [listener]\n}\n{\n  const et = new EventTarget();\n  const listener = () => console.log('Events are fun');\n  et.addEventListener('foo', listener);\n  getEventListeners(et, 'foo'); // [listener]\n}\n</code></pre>"
1430        },
1431        {
1432          "textRaw": "`events.once(emitter, name[, options])`",
1433          "type": "method",
1434          "name": "once",
1435          "meta": {
1436            "added": [
1437              "v11.13.0",
1438              "v10.16.0"
1439            ],
1440            "changes": [
1441              {
1442                "version": "v14.17.0",
1443                "pr-url": "https://github.com/nodejs/node/pull/34912",
1444                "description": "The `signal` option is supported now."
1445              }
1446            ]
1447          },
1448          "signatures": [
1449            {
1450              "return": {
1451                "textRaw": "Returns: {Promise}",
1452                "name": "return",
1453                "type": "Promise"
1454              },
1455              "params": [
1456                {
1457                  "textRaw": "`emitter` {EventEmitter}",
1458                  "name": "emitter",
1459                  "type": "EventEmitter"
1460                },
1461                {
1462                  "textRaw": "`name` {string}",
1463                  "name": "name",
1464                  "type": "string"
1465                },
1466                {
1467                  "textRaw": "`options` {Object}",
1468                  "name": "options",
1469                  "type": "Object",
1470                  "options": [
1471                    {
1472                      "textRaw": "`signal` {AbortSignal} Can be used to cancel waiting for the event.",
1473                      "name": "signal",
1474                      "type": "AbortSignal",
1475                      "desc": "Can be used to cancel waiting for the event."
1476                    }
1477                  ]
1478                }
1479              ]
1480            }
1481          ],
1482          "desc": "<p>Creates a <code>Promise</code> that is fulfilled when the <code>EventEmitter</code> emits the given\nevent or that is rejected if the <code>EventEmitter</code> emits <code>'error'</code> while waiting.\nThe <code>Promise</code> will resolve with an array of all the arguments emitted to the\ngiven event.</p>\n<p>This method is intentionally generic and works with the web platform\n<a href=\"https://dom.spec.whatwg.org/#interface-eventtarget\">EventTarget</a> interface, which has no special\n<code>'error'</code> event semantics and does not listen to the <code>'error'</code> event.</p>\n<pre><code class=\"language-js\">const { once, EventEmitter } = require('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.log('error happened', err);\n  }\n}\n\nrun();\n</code></pre>\n<p>The special handling of the <code>'error'</code> event is only used when <code>events.once()</code>\nis used to wait for another event. If <code>events.once()</code> is used to wait for the\n'<code>error'</code> event itself, then it is treated as any other kind of event without\nspecial handling:</p>\n<pre><code class=\"language-js\">const { EventEmitter, once } = require('events');\n\nconst ee = new EventEmitter();\n\nonce(ee, 'error')\n  .then(([err]) => console.log('ok', err.message))\n  .catch((err) => console.log('error', err.message));\n\nee.emit('error', new Error('boom'));\n\n// Prints: ok boom\n</code></pre>\n<p>An <a href=\"globals.html#globals_class_abortsignal\" class=\"type\">&lt;AbortSignal&gt;</a> can be used to cancel waiting for the event:</p>\n<pre><code class=\"language-js\">const { EventEmitter, once } = require('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(); // Abort waiting for the event\nee.emit('foo'); // Prints: Waiting for the event was canceled!\n</code></pre>",
1483          "modules": [
1484            {
1485              "textRaw": "Awaiting multiple events emitted on `process.nextTick()`",
1486              "name": "awaiting_multiple_events_emitted_on_`process.nexttick()`",
1487              "desc": "<p>There is an edge case worth noting when using the <code>events.once()</code> function\nto await multiple events emitted on in the same batch of <code>process.nextTick()</code>\noperations, or whenever multiple events are emitted synchronously. Specifically,\nbecause the <code>process.nextTick()</code> queue is drained before the <code>Promise</code> microtask\nqueue, and because <code>EventEmitter</code> emits all events synchronously, it is possible\nfor <code>events.once()</code> to miss an event.</p>\n<pre><code class=\"language-js\">const { EventEmitter, once } = require('events');\n\nconst myEE = new EventEmitter();\n\nasync function foo() {\n  await once(myEE, 'bar');\n  console.log('bar');\n\n  // This Promise will never resolve because the 'foo' event will\n  // have already been emitted before the Promise is created.\n  await once(myEE, 'foo');\n  console.log('foo');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('bar');\n  myEE.emit('foo');\n});\n\nfoo().then(() => console.log('done'));\n</code></pre>\n<p>To catch both events, create each of the Promises <em>before</em> awaiting either\nof them, then it becomes possible to use <code>Promise.all()</code>, <code>Promise.race()</code>,\nor <code>Promise.allSettled()</code>:</p>\n<pre><code class=\"language-js\">const { EventEmitter, once } = require('events');\n\nconst myEE = new EventEmitter();\n\nasync function foo() {\n  await Promise.all([once(myEE, 'bar'), once(myEE, 'foo')]);\n  console.log('foo', 'bar');\n}\n\nprocess.nextTick(() => {\n  myEE.emit('bar');\n  myEE.emit('foo');\n});\n\nfoo().then(() => console.log('done'));\n</code></pre>",
1488              "type": "module",
1489              "displayName": "Awaiting multiple events emitted on `process.nextTick()`"
1490            }
1491          ]
1492        },
1493        {
1494          "textRaw": "`events.listenerCount(emitter, eventName)`",
1495          "type": "method",
1496          "name": "listenerCount",
1497          "meta": {
1498            "added": [
1499              "v0.9.12"
1500            ],
1501            "deprecated": [
1502              "v3.2.0"
1503            ],
1504            "changes": []
1505          },
1506          "stability": 0,
1507          "stabilityText": "Deprecated: Use [`emitter.listenerCount()`][] instead.",
1508          "signatures": [
1509            {
1510              "params": [
1511                {
1512                  "textRaw": "`emitter` {EventEmitter} The emitter to query",
1513                  "name": "emitter",
1514                  "type": "EventEmitter",
1515                  "desc": "The emitter to query"
1516                },
1517                {
1518                  "textRaw": "`eventName` {string|symbol} The event name",
1519                  "name": "eventName",
1520                  "type": "string|symbol",
1521                  "desc": "The event name"
1522                }
1523              ]
1524            }
1525          ],
1526          "desc": "<p>A class method that returns the number of listeners for the given <code>eventName</code>\nregistered on the given <code>emitter</code>.</p>\n<pre><code class=\"language-js\">const { EventEmitter, listenerCount } = require('events');\nconst myEmitter = new EventEmitter();\nmyEmitter.on('event', () => {});\nmyEmitter.on('event', () => {});\nconsole.log(listenerCount(myEmitter, 'event'));\n// Prints: 2\n</code></pre>"
1527        },
1528        {
1529          "textRaw": "`events.on(emitter, eventName[, options])`",
1530          "type": "method",
1531          "name": "on",
1532          "meta": {
1533            "added": [
1534              "v13.6.0",
1535              "v12.16.0"
1536            ],
1537            "changes": []
1538          },
1539          "signatures": [
1540            {
1541              "return": {
1542                "textRaw": "Returns: {AsyncIterator} that iterates `eventName` events emitted by the `emitter`",
1543                "name": "return",
1544                "type": "AsyncIterator",
1545                "desc": "that iterates `eventName` events emitted by the `emitter`"
1546              },
1547              "params": [
1548                {
1549                  "textRaw": "`emitter` {EventEmitter}",
1550                  "name": "emitter",
1551                  "type": "EventEmitter"
1552                },
1553                {
1554                  "textRaw": "`eventName` {string|symbol} The name of the event being listened for",
1555                  "name": "eventName",
1556                  "type": "string|symbol",
1557                  "desc": "The name of the event being listened for"
1558                },
1559                {
1560                  "textRaw": "`options` {Object}",
1561                  "name": "options",
1562                  "type": "Object",
1563                  "options": [
1564                    {
1565                      "textRaw": "`signal` {AbortSignal} Can be used to cancel awaiting events.",
1566                      "name": "signal",
1567                      "type": "AbortSignal",
1568                      "desc": "Can be used to cancel awaiting events."
1569                    }
1570                  ]
1571                }
1572              ]
1573            }
1574          ],
1575          "desc": "<pre><code class=\"language-js\">const { on, EventEmitter } = require('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</code></pre>\n<p>Returns an <code>AsyncIterator</code> that iterates <code>eventName</code> events. It will throw\nif the <code>EventEmitter</code> emits <code>'error'</code>. It removes all listeners when\nexiting the loop. The <code>value</code> returned by each iteration is an array\ncomposed of the emitted event arguments.</p>\n<p>An <a href=\"globals.html#globals_class_abortsignal\" class=\"type\">&lt;AbortSignal&gt;</a> can be used to cancel waiting on events:</p>\n<pre><code class=\"language-js\">const { on, EventEmitter } = require('events');\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</code></pre>"
1576        },
1577        {
1578          "textRaw": "`events.setMaxListeners(n[, ...eventTargets])`",
1579          "type": "method",
1580          "name": "setMaxListeners",
1581          "meta": {
1582            "added": [
1583              "v14.17.0"
1584            ],
1585            "changes": []
1586          },
1587          "signatures": [
1588            {
1589              "params": [
1590                {
1591                  "textRaw": "`n` {number} A non-negative number. The maximum number of listeners per `EventTarget` event.",
1592                  "name": "n",
1593                  "type": "number",
1594                  "desc": "A non-negative number. The maximum number of listeners per `EventTarget` event."
1595                },
1596                {
1597                  "textRaw": "`...eventsTargets` {EventTarget[]|EventEmitter[]} Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects.",
1598                  "name": "...eventsTargets",
1599                  "type": "EventTarget[]|EventEmitter[]",
1600                  "desc": "Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects."
1601                }
1602              ]
1603            }
1604          ],
1605          "desc": "<pre><code class=\"language-js\">const {\n  setMaxListeners,\n  EventEmitter\n} = require('events');\n\nconst target = new EventTarget();\nconst emitter = new EventEmitter();\n\nsetMaxListeners(5, target, emitter);\n</code></pre>\n<p><a id=\"event-target-and-event-api\"></a></p>"
1606        }
1607      ]
1608    }
1609  ]
1610}