Skip to content

TlsServer

Defined in: packages/node/src/net/tls-server.ts:52

TLS server accepting encrypted incoming connections.

Example usage:

const server = TlsServer.from({ key, cert });
server.subscribe("secureConnection", (socket) => {
console.log("Client cipher:", socket.getCipher().name);
});
await server.listen(8443, "0.0.0.0");
// ... later
await server.close();

Every event of TcpServer is still emitted, so TcpServerEvents.connection reports the plaintext socket accepted before the handshake. Wait for TlsServerEvents.secureConnection to read or write application data.

The session-resumption events Node.js exposes with a completion callback (newSession, resumeSession and OCSPRequest) are deliberately not forwarded: Node.js falls back to its default behaviour only while no listener is attached, so forwarding them would stall every handshake that nobody subscribed to.

new TlsServer(server): TlsServer

Defined in: packages/node/src/net/stream-server.ts:43

Creates a new StreamServer instance.

Server

The underlying Node.js server.

TlsServer

TcpServer.constructor

get listening(): boolean

Defined in: packages/node/src/net/stream-server.ts:49

Whether the server is currently listening for connections.

boolean

TcpServer.listening


get maxConnections(): number

Defined in: packages/node/src/net/stream-server.ts:54

Maximum number of concurrent connections accepted by the server.

number

set maxConnections(maxConnections): void

Defined in: packages/node/src/net/stream-server.ts:63

Updates the maximum number of concurrent connections.

Connections accepted beyond this limit are dropped.

number

void

TcpServer.maxConnections

addContext(hostname, context): void

Defined in: packages/node/src/net/tls-server.ts:71

Adds a secure context to serve when a client requests hostname through SNI.

string

The server name to match, which may contain wildcards.

TlsSecureContext

The secure context or the options to build one from.

void


address(): InetEndpoint | null

Defined in: packages/node/src/net/tcp-server.ts:89

Returns the endpoint the server is bound to.

InetEndpoint | null

The bound endpoint, or null when the server is not listening.

When the server is bound to a path rather than an IP endpoint. Use IpcServer for those.

TcpServer.address


close(): Promise<void>

Defined in: packages/node/src/net/stream-server.ts:107

Stops the server from accepting new connections. Established connections are not closed; the promise resolves once the last of them ends.

Promise<void>

A promise that resolves when the server is fully closed.

When the server was not listening.

TcpServer.close


getConnections(): Promise<number>

Defined in: packages/node/src/net/stream-server.ts:72

Counts the connections currently handled by the server.

Promise<number>

A promise that resolves with the connection count.

TcpServer.getConnections


getTicketKeys(): Buffer

Defined in: packages/node/src/net/tls-server.ts:93

Returns the keys used to encrypt session tickets.

Sharing them across server instances lets clients resume a session on any of them; they are sensitive key material and must be handled as secrets.

Buffer

The 48-byte session ticket keys.


isSubscribed<K>(event, listener): boolean

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:38

Check if a callback is subscribed to a specific event.

K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"

K

The event name.

Callable<TlsServerEvents[K]>

The callback to check.

boolean

TcpServer.isSubscribed


listen(port, options?): Promise<void>

Defined in: packages/node/src/net/tcp-server.ts:75

Binds the server and resolves once it is listening.

number

The port to listen on. Use 0 to let the system assign one.

Additional listen options.

number

boolean

string

boolean

Default

false

boolean

boolean

AbortSignal

boolean

Promise<void>

A promise that resolves once the server is listening.

When the address is already in use or cannot be bound.

TcpServer.listen


ref(): void

Defined in: packages/node/src/net/stream-server.ts:88

Marks the server as referenced, preventing the Node.js process from exiting while it is listening.

void

TcpServer.ref


setSecureContext(context): void

Defined in: packages/node/src/net/tls-server.ts:81

Replaces the default secure context, affecting connections established after the call.

SecureContextOptions

The options to build the secure context from.

void


setTicketKeys(keys): void

Defined in: packages/node/src/net/tls-server.ts:103

Sets the keys used to encrypt session tickets, affecting connections established after the call.

Buffer

The 48-byte session ticket keys.

void


subscribe<K>(event, listener, options?): Callable | null

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:23

K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"

K

Callable<TlsServerEvents[K]>

EventDispatcherSubscribeOptions

Callable | null

TcpServer.subscribe


unref(): void

Defined in: packages/node/src/net/stream-server.ts:96

Marks the server as unreferenced, allowing the Node.js process to exit even while it is listening.

void

TcpServer.unref


unsubscribe<K>(event, listener): void

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:31

Unsubscribe a callback from a specific event.

K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"

K

The event name.

Callable<TlsServerEvents[K]>

The callback to remove.

void

TcpServer.unsubscribe


wait<K>(event, options?): Promise<TlsServerEvents[K]>

Defined in: packages/async/src/events/event-dispatcher-map-base.ts:45

Wait for the next occurrence of a specific event, optionally matching a predicate.

This is a convenience method that subscribes to the dispatcher, waits for the next event that matches the predicate (if provided), and then unsubscribes automatically.

K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"

K

The event name to wait for.

EventDispatcherWaitOptions<TlsServerEvents[K]>

Optional settings including predicate and abort signal.

Promise<TlsServerEvents[K]>

A promise that resolves with the event arguments as an array.

TcpServer.wait


static from(options?): TlsServer

Defined in: packages/node/src/net/tls-server.ts:60

Creates a new TlsServer instance.

TlsOptions

Options for creating the underlying Node.js server, including the certificate chain and private key to serve.

TlsServer

A new TlsServer instance.

TcpServer.from