since

  v0.1.17

### Hierarchy

- <internal>.Server
  - Server
    - <internal>.Server

## Index

### Constructors

- constructor

### Properties

- connections
- headersTimeout
- keepAliveTimeout
- listening
- maxConnections
- maxHeadersCount
- maxRequestsPerSocket
- requestTimeout
- timeout
- captureRejectionSymbol
- captureRejections
- defaultMaxListeners
- errorMonitor

### Methods

- addListener
- address
- close
- emit
- eventNames
- getConnections
- getMaxListeners
- listen
- listenerCount
- listeners
- off
- on
- once
- prependListener
- prependOnceListener
- rawListeners
- ref
- removeAllListeners
- removeListener
- setMaxListeners
- setTimeout
- unref
- getEventListeners
- listenerCount
- on
- once

## Constructors

### constructor

- new Server(requestListener?: RequestListener): <internal>.Server
- new Server(options: <internal>.ServerOptions, requestListener?: RequestListener): <internal>.Server

- Overrides Server.constructor

  #### Parameters

  - ##### Optional requestListener: RequestListener

  #### Returns <internal>.Server

- Overrides Server.constructor

  #### Parameters

  - ##### options: <internal>.ServerOptions

  - ##### Optional requestListener: RequestListener

  #### Returns <internal>.Server

## Properties

### connections

connections: number

Inherited from Server.connections

### headersTimeout

headersTimeout: number

Limit the amount of time the parser will wait to receive the complete HTTP headers.

In case of inactivity, the rules defined in `server.timeout` apply. However, that inactivity based timeout would still allow the connection to be kept open if the headers are being sent very slowly (by default, up to a byte per 2 minutes). In order to prevent this, whenever header data arrives an additional check is made that more than `server.headersTimeout` milliseconds has not passed since the connection was established. If the check fails, a `'timeout'`event is emitted on the server object, and (by default) the socket is destroyed. See `server.timeout` for more information on how timeout behavior can be customized.

since

  v11.3.0, v10.14.0

### keepAliveTimeout

keepAliveTimeout: number

The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. If the server receives new data before the keep-alive timeout has fired, it will reset the regular inactivity timeout, i.e.,`server.timeout`.

A value of `0` will disable the keep-alive timeout behavior on incoming connections. A value of `0` makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.

The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections.

since

  v8.0.0

### listening

listening: boolean

Inherited from Server.listening

Indicates whether or not the server is listening for connections.

since

  v5.7.0

### maxConnections

maxConnections: number

Inherited from Server.maxConnections

Set this property to reject connections when the server's connection count gets high.

It is not recommended to use this option once a socket has been sent to a child with `child_process.fork()`.

since

  v0.2.0

### maxHeadersCount

maxHeadersCount: number

Limits maximum incoming headers count. If set to 0, no limit will be applied.

since

  v0.7.0

### maxRequestsPerSocket

maxRequestsPerSocket: number

The maximum number of requests socket can handle before closing keep alive connection.

A value of `0` will disable the limit.

When the limit is reached it will set the `Connection` header value to `close`, but will not actually close the connection, subsequent requests sent after the limit is reached will get `503 Service Unavailable` as a response.

since

  v16.10.0

### requestTimeout

requestTimeout: number

Sets the timeout value in milliseconds for receiving the entire request from the client.

If the timeout expires, the server responds with status 408 without forwarding the request to the request listener and then closes the connection.

It must be set to a non-zero value (e.g. 120 seconds) to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front.

since

  v14.11.0

### timeout

timeout: number

The number of milliseconds of inactivity before a socket is presumed to have timed out.

A value of `0` will disable the timeout behavior on incoming connections.

The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections.

since

  v0.9.12

### Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Inherited from Server.captureRejectionSymbol

### Static captureRejections

captureRejections: boolean

Inherited from Server.captureRejections

Sets or gets the default captureRejection value for all emitters.

### Static defaultMaxListeners

defaultMaxListeners: number

Inherited from Server.defaultMaxListeners

### Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

Inherited from Server.errorMonitor

This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called.

Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted, therefore the process will still crash if no regular `'error'` listener is installed.

## Methods

### addListener

- addListener(event: string, listener: (...args: any[]) => void): <internal>.Server
- addListener(event: "close", listener: () => void): <internal>.Server
- addListener(event: "connection", listener: (socket: Socket) => void): <internal>.Server
- addListener(event: "error", listener: (err: <internal>.Error) => void): <internal>.Server
- addListener(event: "listening", listener: () => void): <internal>.Server
- addListener(event: "checkContinue", listener: RequestListener): <internal>.Server
- addListener(event: "checkExpectation", listener: RequestListener): <internal>.Server
- addListener(event: "clientError", listener: (err: <internal>.Error, socket: <internal>.Duplex) => void): <internal>.Server
- addListener(event: "connect", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server
- addListener(event: "request", listener: RequestListener): <internal>.Server
- addListener(event: "upgrade", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server

- Overrides Server.addListener

  events.EventEmitter

  1. close
  2. connection
  3. error
  4. listening

  #### Parameters

  - ##### event: string

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.addListener

  #### Parameters

  - ##### event: "close"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides Server.addListener

  #### Parameters

  - ##### event: "connection"

  - ##### listener: (socket: Socket) => void

    - - (socket: Socket): void

      - #### Parameters

        - ##### socket: Socket

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.addListener

  #### Parameters

  - ##### event: "error"

  - ##### listener: (err: <internal>.Error) => void

    - - (err: <internal>.Error): void

      - #### Parameters

        - ##### err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.addListener

  #### Parameters

  - ##### event: "listening"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "checkContinue"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "clientError"

  - ##### listener: (err: <internal>.Error, socket: <internal>.Duplex) => void

    - - (err: <internal>.Error, socket: <internal>.Duplex): void

      - #### Parameters

        - ##### err: <internal>.Error

        - ##### socket: <internal>.Duplex

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "connect"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "request"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.addListener

  #### Parameters

  - ##### event: "upgrade"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

### address

- address(): string | <internal>.AddressInfo

- Inherited from Server.address

  Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening on an IP socket (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.

  For a server listening on a pipe or Unix domain socket, the name is returned as a string.

      const server = net.createServer((socket) => {
        socket.end('goodbye\n');
      }).on('error', (err) => {
        // Handle errors here.
        throw err;
      });

      // Grab an arbitrary unused port.
      server.listen(() => {
        console.log('opened server on', server.address());
      });

  `server.address()` returns `null` before the `'listening'` event has been emitted or after calling `server.close()`.

  since

    v0.1.90

  #### Returns string | <internal>.AddressInfo

### close

- close(callback?: (err?: <internal>.Error) => void): <internal>.Server

- Inherited from Server.close

  Stops the server from accepting new connections and keeps existing connections. This function is asynchronous, the server is finally closed when all connections are ended and the server emits a `'close'` event. The optional `callback` will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its only argument if the server was not open when it was closed.

  since

    v0.1.90

  #### Parameters

  - ##### Optional callback: (err?: <internal>.Error) => void

    Called when the server is closed.

    - - (err?: <internal>.Error): void

      - #### Parameters

        - ##### Optional err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

### emit

- emit(event: string, ...args: any[]): boolean
- emit(event: "close"): boolean
- emit(event: "connection", socket: Socket): boolean
- emit(event: "error", err: <internal>.Error): boolean
- emit(event: "listening"): boolean
- emit(event: "checkContinue", req: IncomingMessage, res: ServerResponse): boolean
- emit(event: "checkExpectation", req: IncomingMessage, res: ServerResponse): boolean
- emit(event: "clientError", err: <internal>.Error, socket: <internal>.Duplex): boolean
- emit(event: "connect", req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): boolean
- emit(event: "request", req: IncomingMessage, res: ServerResponse): boolean
- emit(event: "upgrade", req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): boolean

- Overrides Server.emit

  Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments to each.

  Returns `true` if the event had listeners, `false` otherwise.

      const EventEmitter = require('events');
      const myEmitter = new EventEmitter();

      // First listener
      myEmitter.on('event', function firstListener() {
        console.log('Helloooo! first listener');
      });
      // Second listener
      myEmitter.on('event', function secondListener(arg1, arg2) {
        console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
      });
      // Third listener
      myEmitter.on('event', function thirdListener(...args) {
        const parameters = args.join(', ');
        console.log(`event with parameters ${parameters} in third listener`);
      });

      console.log(myEmitter.listeners('event'));

      myEmitter.emit('event', 1, 2, 3, 4, 5);

      // Prints:
      // [
      //   [Function: firstListener],
      //   [Function: secondListener],
      //   [Function: thirdListener]
      // ]
      // Helloooo! first listener
      // event with parameters 1, 2 in second listener
      // event with parameters 1, 2, 3, 4, 5 in third listener

  #### Parameters

  - ##### event: string

  - ##### Rest ...args: any[]

  #### Returns boolean

- Overrides Server.emit

  #### Parameters

  - ##### event: "close"

  #### Returns boolean

- Overrides Server.emit

  #### Parameters

  - ##### event: "connection"

  - ##### socket: Socket

  #### Returns boolean

- Overrides Server.emit

  #### Parameters

  - ##### event: "error"

  - ##### err: <internal>.Error

  #### Returns boolean

- Overrides Server.emit

  #### Parameters

  - ##### event: "listening"

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "checkContinue"

  - ##### req: IncomingMessage

  - ##### res: ServerResponse

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### req: IncomingMessage

  - ##### res: ServerResponse

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "clientError"

  - ##### err: <internal>.Error

  - ##### socket: <internal>.Duplex

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "connect"

  - ##### req: IncomingMessage

  - ##### socket: <internal>.Duplex

  - ##### head: <internal>.Buffer

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "request"

  - ##### req: IncomingMessage

  - ##### res: ServerResponse

  #### Returns boolean

- Overrides NetServer.emit

  #### Parameters

  - ##### event: "upgrade"

  - ##### req: IncomingMessage

  - ##### socket: <internal>.Duplex

  - ##### head: <internal>.Buffer

  #### Returns boolean

### eventNames

- eventNames(): (string | symbol)[]

- Inherited from Server.eventNames

  Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s.

      const EventEmitter = require('events');
      const myEE = new EventEmitter();
      myEE.on('foo', () => {});
      myEE.on('bar', () => {});

      const sym = Symbol('symbol');
      myEE.on(sym, () => {});

      console.log(myEE.eventNames());
      // Prints: [ 'foo', 'bar', Symbol(symbol) ]

  since

    v6.0.0

  #### Returns (string | symbol)[]

### getConnections

- getConnections(cb: (error: <internal>.Error, count: number) => void): void

- Inherited from Server.getConnections

  Asynchronously get the number of concurrent connections on the server. Works when sockets were sent to forks.

  Callback should take two arguments `err` and `count`.

  since

    v0.9.7

  #### Parameters

  - ##### cb: (error: <internal>.Error, count: number) => void

    - - (error: <internal>.Error, count: number): void

      - #### Parameters

        - ##### error: <internal>.Error

        - ##### count: number

        #### Returns void

### getMaxListeners

- getMaxListeners(): number

- Inherited from Server.getMaxListeners

  Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to defaultMaxListeners.

  since

    v1.0.0

  #### Returns number

### listen

- listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): <internal>.Server
- listen(port?: number, hostname?: string, listeningListener?: () => void): <internal>.Server
- listen(port?: number, backlog?: number, listeningListener?: () => void): <internal>.Server
- listen(port?: number, listeningListener?: () => void): <internal>.Server
- listen(path: string, backlog?: number, listeningListener?: () => void): <internal>.Server
- listen(path: string, listeningListener?: () => void): <internal>.Server
- listen(options: ListenOptions, listeningListener?: () => void): <internal>.Server
- listen(handle: any, backlog?: number, listeningListener?: () => void): <internal>.Server
- listen(handle: any, listeningListener?: () => void): <internal>.Server

- Inherited from Server.listen

  Start a server listening for connections. A `net.Server` can be a TCP or an `IPC` server depending on what it listens to.

  Possible signatures:

  - `server.listen(handle[, backlog][, callback])`
  - `server.listen(options[, callback])`
  - `server.listen(path[, backlog][, callback])` for `IPC` servers
  - `server.listen([port[, host[, backlog]]][, callback])` for TCP servers

  This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. The last parameter `callback`will be added as a listener for the `'listening'` event.

  All `listen()` methods can take a `backlog` parameter to specify the maximum length of the queue of pending connections. The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn`on Linux. The default value of this parameter is 511 (not 512).

  All Socket are set to `SO_REUSEADDR` (see `socket(7)` for details).

  The `server.listen()` method can be called again if and only if there was an error during the first `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.

  One of the most common errors raised when listening is `EADDRINUSE`. This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry after a certain amount of time:

      server.on('error', (e) => {
        if (e.code === 'EADDRINUSE') {
          console.log('Address in use, retrying...');
          setTimeout(() => {
            server.close();
            server.listen(PORT, HOST);
          }, 1000);
        }
      });

  #### Parameters

  - ##### Optional port: number

  - ##### Optional hostname: string

  - ##### Optional backlog: number

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### Optional port: number

  - ##### Optional hostname: string

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### Optional port: number

  - ##### Optional backlog: number

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### Optional port: number

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### path: string

  - ##### Optional backlog: number

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### path: string

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### options: ListenOptions

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### handle: any

  - ##### Optional backlog: number

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Inherited from Server.listen

  #### Parameters

  - ##### handle: any

  - ##### Optional listeningListener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

### listenerCount

- listenerCount(eventName: string | symbol): number

- Inherited from Server.listenerCount

  Returns the number of listeners listening to the event named `eventName`.

  since

    v3.2.0

  #### Parameters

  - ##### eventName: string | symbol

    The name of the event being listened for

  #### Returns number

### listeners

- listeners(eventName: string | symbol): Function[]

- Inherited from Server.listeners

  Returns a copy of the array of listeners for the event named `eventName`.

      server.on('connection', (stream) => {
        console.log('someone connected!');
      });
      console.log(util.inspect(server.listeners('connection')));
      // Prints: [ [Function] ]

  since

    v0.1.26

  #### Parameters

  - ##### eventName: string | symbol

  #### Returns Function[]

### off

- off(eventName: string | symbol, listener: (...args: any[]) => void): <internal>.Server

- Inherited from Server.off

  Alias for `emitter.removeListener()`.

  since

    v10.0.0

  #### Parameters

  - ##### eventName: string | symbol

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

### on

- on(event: string, listener: (...args: any[]) => void): <internal>.Server
- on(event: "close", listener: () => void): <internal>.Server
- on(event: "connection", listener: (socket: Socket) => void): <internal>.Server
- on(event: "error", listener: (err: <internal>.Error) => void): <internal>.Server
- on(event: "listening", listener: () => void): <internal>.Server
- on(event: "checkContinue", listener: RequestListener): <internal>.Server
- on(event: "checkExpectation", listener: RequestListener): <internal>.Server
- on(event: "clientError", listener: (err: <internal>.Error, socket: <internal>.Duplex) => void): <internal>.Server
- on(event: "connect", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server
- on(event: "request", listener: RequestListener): <internal>.Server
- on(event: "upgrade", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server

- Overrides Server.on

  Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName`and `listener` will result in the `listener` being added, and called, multiple times.

      server.on('connection', (stream) => {
        console.log('someone connected!');
      });

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  By default, event listeners are invoked in the order they are added. The`emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array.

      const myEE = new EventEmitter();
      myEE.on('foo', () => console.log('a'));
      myEE.prependListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      //   b
      //   a

  #### Parameters

  - ##### event: string

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.on

  #### Parameters

  - ##### event: "close"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides Server.on

  #### Parameters

  - ##### event: "connection"

  - ##### listener: (socket: Socket) => void

    - - (socket: Socket): void

      - #### Parameters

        - ##### socket: Socket

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.on

  #### Parameters

  - ##### event: "error"

  - ##### listener: (err: <internal>.Error) => void

    - - (err: <internal>.Error): void

      - #### Parameters

        - ##### err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.on

  #### Parameters

  - ##### event: "listening"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "checkContinue"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "clientError"

  - ##### listener: (err: <internal>.Error, socket: <internal>.Duplex) => void

    - - (err: <internal>.Error, socket: <internal>.Duplex): void

      - #### Parameters

        - ##### err: <internal>.Error

        - ##### socket: <internal>.Duplex

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "connect"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "request"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.on

  #### Parameters

  - ##### event: "upgrade"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

### once

- once(event: string, listener: (...args: any[]) => void): <internal>.Server
- once(event: "close", listener: () => void): <internal>.Server
- once(event: "connection", listener: (socket: Socket) => void): <internal>.Server
- once(event: "error", listener: (err: <internal>.Error) => void): <internal>.Server
- once(event: "listening", listener: () => void): <internal>.Server
- once(event: "checkContinue", listener: RequestListener): <internal>.Server
- once(event: "checkExpectation", listener: RequestListener): <internal>.Server
- once(event: "clientError", listener: (err: <internal>.Error, socket: <internal>.Duplex) => void): <internal>.Server
- once(event: "connect", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server
- once(event: "request", listener: RequestListener): <internal>.Server
- once(event: "upgrade", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server

- Overrides Server.once

  Adds a one-time `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked.

      server.once('connection', (stream) => {
        console.log('Ah, we have our first user!');
      });

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  By default, event listeners are invoked in the order they are added. The`emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array.

      const myEE = new EventEmitter();
      myEE.once('foo', () => console.log('a'));
      myEE.prependOnceListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      //   b
      //   a

  #### Parameters

  - ##### event: string

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.once

  #### Parameters

  - ##### event: "close"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides Server.once

  #### Parameters

  - ##### event: "connection"

  - ##### listener: (socket: Socket) => void

    - - (socket: Socket): void

      - #### Parameters

        - ##### socket: Socket

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.once

  #### Parameters

  - ##### event: "error"

  - ##### listener: (err: <internal>.Error) => void

    - - (err: <internal>.Error): void

      - #### Parameters

        - ##### err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.once

  #### Parameters

  - ##### event: "listening"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "checkContinue"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "clientError"

  - ##### listener: (err: <internal>.Error, socket: <internal>.Duplex) => void

    - - (err: <internal>.Error, socket: <internal>.Duplex): void

      - #### Parameters

        - ##### err: <internal>.Error

        - ##### socket: <internal>.Duplex

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "connect"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "request"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.once

  #### Parameters

  - ##### event: "upgrade"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

### prependListener

- prependListener(event: string, listener: (...args: any[]) => void): <internal>.Server
- prependListener(event: "close", listener: () => void): <internal>.Server
- prependListener(event: "connection", listener: (socket: Socket) => void): <internal>.Server
- prependListener(event: "error", listener: (err: <internal>.Error) => void): <internal>.Server
- prependListener(event: "listening", listener: () => void): <internal>.Server
- prependListener(event: "checkContinue", listener: RequestListener): <internal>.Server
- prependListener(event: "checkExpectation", listener: RequestListener): <internal>.Server
- prependListener(event: "clientError", listener: (err: <internal>.Error, socket: <internal>.Duplex) => void): <internal>.Server
- prependListener(event: "connect", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server
- prependListener(event: "request", listener: RequestListener): <internal>.Server
- prependListener(event: "upgrade", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server

- Overrides Server.prependListener

  Adds the `listener` function to the beginning of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName`and `listener` will result in the `listener` being added, and called, multiple times.

      server.prependListener('connection', (stream) => {
        console.log('someone connected!');
      });

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  #### Parameters

  - ##### event: string

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependListener

  #### Parameters

  - ##### event: "close"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependListener

  #### Parameters

  - ##### event: "connection"

  - ##### listener: (socket: Socket) => void

    - - (socket: Socket): void

      - #### Parameters

        - ##### socket: Socket

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependListener

  #### Parameters

  - ##### event: "error"

  - ##### listener: (err: <internal>.Error) => void

    - - (err: <internal>.Error): void

      - #### Parameters

        - ##### err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependListener

  #### Parameters

  - ##### event: "listening"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "checkContinue"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "clientError"

  - ##### listener: (err: <internal>.Error, socket: <internal>.Duplex) => void

    - - (err: <internal>.Error, socket: <internal>.Duplex): void

      - #### Parameters

        - ##### err: <internal>.Error

        - ##### socket: <internal>.Duplex

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "connect"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "request"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependListener

  #### Parameters

  - ##### event: "upgrade"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

### prependOnceListener

- prependOnceListener(event: string, listener: (...args: any[]) => void): <internal>.Server
- prependOnceListener(event: "close", listener: () => void): <internal>.Server
- prependOnceListener(event: "connection", listener: (socket: Socket) => void): <internal>.Server
- prependOnceListener(event: "error", listener: (err: <internal>.Error) => void): <internal>.Server
- prependOnceListener(event: "listening", listener: () => void): <internal>.Server
- prependOnceListener(event: "checkContinue", listener: RequestListener): <internal>.Server
- prependOnceListener(event: "checkExpectation", listener: RequestListener): <internal>.Server
- prependOnceListener(event: "clientError", listener: (err: <internal>.Error, socket: <internal>.Duplex) => void): <internal>.Server
- prependOnceListener(event: "connect", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server
- prependOnceListener(event: "request", listener: RequestListener): <internal>.Server
- prependOnceListener(event: "upgrade", listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void): <internal>.Server

- Overrides Server.prependOnceListener

  Adds a one-time `listener` function for the event named `eventName` to the_beginning_ of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked.

      server.prependOnceListener('connection', (stream) => {
        console.log('Ah, we have our first user!');
      });

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  #### Parameters

  - ##### event: string

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependOnceListener

  #### Parameters

  - ##### event: "close"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependOnceListener

  #### Parameters

  - ##### event: "connection"

  - ##### listener: (socket: Socket) => void

    - - (socket: Socket): void

      - #### Parameters

        - ##### socket: Socket

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependOnceListener

  #### Parameters

  - ##### event: "error"

  - ##### listener: (err: <internal>.Error) => void

    - - (err: <internal>.Error): void

      - #### Parameters

        - ##### err: <internal>.Error

        #### Returns void

  #### Returns <internal>.Server

- Overrides Server.prependOnceListener

  #### Parameters

  - ##### event: "listening"

  - ##### listener: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "checkContinue"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "checkExpectation"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "clientError"

  - ##### listener: (err: <internal>.Error, socket: <internal>.Duplex) => void

    - - (err: <internal>.Error, socket: <internal>.Duplex): void

      - #### Parameters

        - ##### err: <internal>.Error

        - ##### socket: <internal>.Duplex

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "connect"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "request"

  - ##### listener: RequestListener

  #### Returns <internal>.Server

- Overrides NetServer.prependOnceListener

  #### Parameters

  - ##### event: "upgrade"

  - ##### listener: (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer) => void

    - - (req: IncomingMessage, socket: <internal>.Duplex, head: <internal>.Buffer): void

      - #### Parameters

        - ##### req: IncomingMessage

        - ##### socket: <internal>.Duplex

        - ##### head: <internal>.Buffer

        #### Returns void

  #### Returns <internal>.Server

### rawListeners

- rawListeners(eventName: string | symbol): Function[]

- Inherited from Server.rawListeners

  Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`).

      const emitter = new EventEmitter();
      emitter.once('log', () => console.log('log once'));

      // Returns a new Array with a function `onceWrapper` which has a property
      // `listener` which contains the original listener bound above
      const listeners = emitter.rawListeners('log');
      const logFnWrapper = listeners[0];

      // Logs "log once" to the console and does not unbind the `once` event
      logFnWrapper.listener();

      // Logs "log once" to the console and removes the listener
      logFnWrapper();

      emitter.on('log', () => console.log('log persistently'));
      // Will return a new Array with a single function bound by `.on()` above
      const newListeners = emitter.rawListeners('log');

      // Logs "log persistently" twice
      newListeners[0]();
      emitter.emit('log');

  since

    v9.4.0

  #### Parameters

  - ##### eventName: string | symbol

  #### Returns Function[]

### ref

- ref(): <internal>.Server

- Inherited from Server.ref

  Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will_not_ let the program exit if it's the only server left (the default behavior). If the server is `ref`ed calling `ref()` again will have no effect.

  since

    v0.9.1

  #### Returns <internal>.Server

### removeAllListeners

- removeAllListeners(event?: string | symbol): <internal>.Server

- Inherited from Server.removeAllListeners

  Removes all listeners, or those of the specified `eventName`.

  It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams).

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  since

    v0.1.26

  #### Parameters

  - ##### Optional event: string | symbol

  #### Returns <internal>.Server

### removeListener

- removeListener(eventName: string | symbol, listener: (...args: any[]) => void): <internal>.Server

- Inherited from Server.removeListener

  Removes the specified `listener` from the listener array for the event named`eventName`.

      const callback = (stream) => {
        console.log('someone connected!');
      };
      server.on('connection', callback);
      // ...
      server.removeListener('connection', callback);

  `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance.

  Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls after emitting and_before_ the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected.

      const myEmitter = new MyEmitter();

      const callbackA = () => {
        console.log('A');
        myEmitter.removeListener('event', callbackB);
      };

      const callbackB = () => {
        console.log('B');
      };

      myEmitter.on('event', callbackA);

      myEmitter.on('event', callbackB);

      // callbackA removes listener callbackB but it will still be called.
      // Internal listener array at time of emit [callbackA, callbackB]
      myEmitter.emit('event');
      // Prints:
      //   A
      //   B

      // callbackB is now removed.
      // Internal listener array [callbackA]
      myEmitter.emit('event');
      // Prints:
      //   A

  Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated.

  When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')`listener is removed:

      const ee = new EventEmitter();

      function pong() {
        console.log('pong');
      }

      ee.on('ping', pong);
      ee.once('ping', pong);
      ee.removeListener('ping', pong);

      ee.emit('ping');
      ee.emit('ping');

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  since

    v0.1.26

  #### Parameters

  - ##### eventName: string | symbol

  - ##### listener: (...args: any[]) => void

    - - (...args: any[]): void

      - #### Parameters

        - ##### Rest ...args: any[]

        #### Returns void

  #### Returns <internal>.Server

### setMaxListeners

- setMaxListeners(n: number): <internal>.Server

- Inherited from Server.setMaxListeners

  By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to`Infinity` (or `0`) to indicate an unlimited number of listeners.

  Returns a reference to the `EventEmitter`, so that calls can be chained.

  since

    v0.3.5

  #### Parameters

  - ##### n: number

  #### Returns <internal>.Server

### setTimeout

- setTimeout(msecs?: number, callback?: () => void): <internal>.Server
- setTimeout(callback: () => void): <internal>.Server

- Sets the timeout value for sockets, and emits a `'timeout'` event on the Server object, passing the socket as an argument, if a timeout occurs.

  If there is a `'timeout'` event listener on the Server object, then it will be called with the timed-out socket as an argument.

  By default, the Server does not timeout sockets. However, if a callback is assigned to the Server's `'timeout'` event, timeouts must be handled explicitly.

  since

    v0.9.12

  #### Parameters

  - ##### Optional msecs: number

  - ##### Optional callback: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

- #### Parameters

  - ##### callback: () => void

    - - (): void

      - #### Returns void

  #### Returns <internal>.Server

### unref

- unref(): <internal>.Server

- Inherited from Server.unref

  Calling `unref()` on a server will allow the program to exit if this is the only active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.

  since

    v0.9.1

  #### Returns <internal>.Server

### Static getEventListeners

- getEventListeners(emitter: <internal>.EventEmitter | DOMEventTarget, name: string | symbol): Function[]

- Inherited from Server.getEventListeners

  Returns a copy of the array of listeners for the event named `eventName`.

  For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter.

  For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes.

      const { getEventListeners, EventEmitter } = require('events');

      {
        const ee = new EventEmitter();
        const listener = () => console.log('Events are fun');
        ee.on('foo', listener);
        getEventListeners(ee, 'foo'); // [listener]
      }
      {
        const et = new EventTarget();
        const listener = () => console.log('Events are fun');
        et.addEventListener('foo', listener);
        getEventListeners(et, 'foo'); // [listener]
      }

  since

    v15.2.0

  #### Parameters

  - ##### emitter: <internal>.EventEmitter | DOMEventTarget

  - ##### name: string | symbol

  #### Returns Function[]

### Static listenerCount

- listenerCount(emitter: <internal>.EventEmitter, eventName: string | symbol): number

- Inherited from Server.listenerCount

  A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.

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

  since

    v0.9.12

  deprecated

    Since v3.2.0 - Use `listenerCount` instead.

  #### Parameters

  - ##### emitter: <internal>.EventEmitter

    The emitter to query

  - ##### eventName: string | symbol

    The event name

  #### Returns number

### Static on

- on(emitter: <internal>.EventEmitter, eventName: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>

- Inherited from Server.on

  ```js const { on, EventEmitter } = require('events');

  (async () => { const ee = new EventEmitter();

  // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); });

  for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })();

      Returns an `AsyncIterator` that iterates `eventName` events. It will throw
      if the `EventEmitter` emits `'error'`. It removes all listeners when
      exiting the loop. The `value` returned by each iteration is an array
      composed of the emitted event arguments.

      An `AbortSignal` can be used to cancel waiting on events:

      ```js
      const { on, EventEmitter } = require('events');
      const ac = new AbortController();

      (async () => {
        const ee = new EventEmitter();

        // Emit later on
        process.nextTick(() => {
          ee.emit('foo', 'bar');
          ee.emit('foo', 42);
        });

        for await (const event of on(ee, 'foo', { signal: ac.signal })) {
          // The execution of this inner block is synchronous and it
          // processes one event at a time (even with await). Do not use
          // if concurrent execution is required.
          console.log(event); // prints ['bar'] [42]
        }
        // Unreachable here
      })();

      process.nextTick(() => ac.abort());

  since

    v13.6.0, v12.16.0

  #### Parameters

  - ##### emitter: <internal>.EventEmitter

  - ##### eventName: string

    The name of the event being listened for

  - ##### Optional options: StaticEventEmitterOptions

  #### Returns AsyncIterableIterator<any>

  that iterates `eventName` events emitted by the `emitter`

### Static once

- once(emitter: NodeEventTarget, eventName: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>
- once(emitter: DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>

- Inherited from Server.once

  Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event.

  This method is intentionally generic and works with the web platform EventTarget interface, which has no special`'error'` event semantics and does not listen to the `'error'` event.

      const { once, EventEmitter } = require('events');

      async function run() {
        const ee = new EventEmitter();

        process.nextTick(() => {
          ee.emit('myevent', 42);
        });

        const [value] = await once(ee, 'myevent');
        console.log(value);

        const err = new Error('kaboom');
        process.nextTick(() => {
          ee.emit('error', err);
        });

        try {
          await once(ee, 'myevent');
        } catch (err) {
          console.log('error happened', err);
        }
      }

      run();

  The special handling of the `'error'` event is only used when `events.once()`is used to wait for another event. If `events.once()` is used to wait for the '`error'` event itself, then it is treated as any other kind of event without special handling:

      const { EventEmitter, once } = require('events');

      const ee = new EventEmitter();

      once(ee, 'error')
        .then(([err]) => console.log('ok', err.message))
        .catch((err) => console.log('error', err.message));

      ee.emit('error', new Error('boom'));

      // Prints: ok boom

  An `AbortSignal` can be used to cancel waiting for the event:

      const { EventEmitter, once } = require('events');

      const ee = new EventEmitter();
      const ac = new AbortController();

      async function foo(emitter, event, signal) {
        try {
          await once(emitter, event, { signal });
          console.log('event emitted!');
        } catch (error) {
          if (error.name === 'AbortError') {
            console.error('Waiting for the event was canceled!');
          } else {
            console.error('There was an error', error.message);
          }
        }
      }

      foo(ee, 'foo', ac.signal);
      ac.abort(); // Abort waiting for the event
      ee.emit('foo'); // Prints: Waiting for the event was canceled!

  since

    v11.13.0, v10.16.0

  #### Parameters

  - ##### emitter: NodeEventTarget

  - ##### eventName: string | symbol

  - ##### Optional options: StaticEventEmitterOptions

  #### Returns Promise<any[]>

- Inherited from Server.once

  #### Parameters

  - ##### emitter: DOMEventTarget

  - ##### eventName: string

  - ##### Optional options: StaticEventEmitterOptions

  #### Returns Promise<any[]>

Generated using TypeDoc