Server

Net. Server

A Server object is a wrapper around a TCP listener.

Constructor

new Server() → {Server}

Creates a new Server instance.

Source:
Fires:
  • event:listening - Emitted when the server has been bound.
  • event:connection - Emitted when a new connection is made.
  • event:close - Emitted when the server stops accepting new connections.
  • event:error - Emitted when an error occurs.
Returns:
Type:
Server

An instance of the TCP Server class.

Methods

accept() → {Promise.<Socket>}

Waits for a TCP client to connect and accepts the connection.

Source:
Returns:
Type:
Promise.<Socket>
  • A Socket object representing the connected client.

address() → {SocketHost}

Returns the bound address, the address family name and port of the socket.

Source:
Returns:
Type:
SocketHost

The host information where the server is listening.

(async) close()

Stops the server from accepting new connections.

Source:

(async) listen(port, host) → {Promise.<SocketHost>}

Starts listening for incoming connections.

Source:
Parameters:
Name Type Description
port string | number

The port number or string on which the server should listen.

host string

The hostname or IP address on which the server will listen.

Returns:
Type:
Promise.<SocketHost>

The host information where the server is listening.