Server

HTTP. Server

An object capable of serving HTTP requests.

Constructor

new Server() → {Server}

Creates a new Server instance.

Source:
Fires:
  • event:request - Emitted each time there is a request.
  • event:close - Emitted when the server closes.
  • event:clientError - Emitted when a client connection emits an 'error' event.
Returns:
Type:
Server

An instance of the HTTP Server class.

Methods

accept() → {Promise.<Connection>}

Waits for a client to connect and accepts the HTTP request.

Source:
Returns:
Type:
Promise.<Connection>

An object representing an HTTP connection.

(async) close()

Stops the server from accepting new connections.

Source:

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

Starts listening for incoming HTTP 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.