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");// ... laterawait 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.
Extends
Section titled “Extends”TcpServer<tls.Server,TlsServerEvents>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TlsServer(
server):TlsServer
Defined in: packages/node/src/net/stream-server.ts:43
Creates a new StreamServer instance.
Parameters
Section titled “Parameters”server
Section titled “server”Server
The underlying Node.js server.
Returns
Section titled “Returns”TlsServer
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”listening
Section titled “listening”Get Signature
Section titled “Get Signature”get listening():
boolean
Defined in: packages/node/src/net/stream-server.ts:49
Whether the server is currently listening for connections.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”maxConnections
Section titled “maxConnections”Get Signature
Section titled “Get Signature”get maxConnections():
number
Defined in: packages/node/src/net/stream-server.ts:54
Maximum number of concurrent connections accepted by the server.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”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.
Parameters
Section titled “Parameters”maxConnections
Section titled “maxConnections”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”addContext()
Section titled “addContext()”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.
Parameters
Section titled “Parameters”hostname
Section titled “hostname”string
The server name to match, which may contain wildcards.
context
Section titled “context”The secure context or the options to build one from.
Returns
Section titled “Returns”void
address()
Section titled “address()”address():
InetEndpoint|null
Defined in: packages/node/src/net/tcp-server.ts:89
Returns the endpoint the server is bound to.
Returns
Section titled “Returns”InetEndpoint | null
The bound endpoint, or null when the server is not listening.
Throws
Section titled “Throws”When the server is bound to a path rather than an IP endpoint. Use IpcServer for those.
Inherited from
Section titled “Inherited from”close()
Section titled “close()”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.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the server is fully closed.
Throws
Section titled “Throws”When the server was not listening.
Inherited from
Section titled “Inherited from”getConnections()
Section titled “getConnections()”getConnections():
Promise<number>
Defined in: packages/node/src/net/stream-server.ts:72
Counts the connections currently handled by the server.
Returns
Section titled “Returns”Promise<number>
A promise that resolves with the connection count.
Inherited from
Section titled “Inherited from”getTicketKeys()
Section titled “getTicketKeys()”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.
Returns
Section titled “Returns”Buffer
The 48-byte session ticket keys.
isSubscribed()
Section titled “isSubscribed()”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.
Type Parameters
Section titled “Type Parameters”K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"
Parameters
Section titled “Parameters”K
The event name.
listener
Section titled “listener”Callable<TlsServerEvents[K]>
The callback to check.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”listen()
Section titled “listen()”listen(
port,options?):Promise<void>
Defined in: packages/node/src/net/tcp-server.ts:75
Binds the server and resolves once it is listening.
Parameters
Section titled “Parameters”number
The port to listen on. Use 0 to let the system assign one.
options?
Section titled “options?”Additional listen options.
backlog?
Section titled “backlog?”number
exclusive?
Section titled “exclusive?”boolean
string
ipv6Only?
Section titled “ipv6Only?”boolean
Default
falsereadableAll?
Section titled “readableAll?”boolean
reusePort?
Section titled “reusePort?”boolean
signal?
Section titled “signal?”AbortSignal
writableAll?
Section titled “writableAll?”boolean
Returns
Section titled “Returns”Promise<void>
A promise that resolves once the server is listening.
Throws
Section titled “Throws”When the address is already in use or cannot be bound.
Inherited from
Section titled “Inherited from”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.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”setSecureContext()
Section titled “setSecureContext()”setSecureContext(
context):void
Defined in: packages/node/src/net/tls-server.ts:81
Replaces the default secure context, affecting connections established after the call.
Parameters
Section titled “Parameters”context
Section titled “context”SecureContextOptions
The options to build the secure context from.
Returns
Section titled “Returns”void
setTicketKeys()
Section titled “setTicketKeys()”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.
Parameters
Section titled “Parameters”Buffer
The 48-byte session ticket keys.
Returns
Section titled “Returns”void
subscribe()
Section titled “subscribe()”subscribe<
K>(event,listener,options?):Callable|null
Defined in: packages/async/src/events/event-dispatcher-map-base.ts:23
Type Parameters
Section titled “Type Parameters”K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”Callable<TlsServerEvents[K]>
options?
Section titled “options?”EventDispatcherSubscribeOptions
Returns
Section titled “Returns”Callable | null
Inherited from
Section titled “Inherited from”unref()
Section titled “unref()”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.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”unsubscribe()
Section titled “unsubscribe()”unsubscribe<
K>(event,listener):void
Defined in: packages/async/src/events/event-dispatcher-map-base.ts:31
Unsubscribe a callback from a specific event.
Type Parameters
Section titled “Type Parameters”K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"
Parameters
Section titled “Parameters”K
The event name.
listener
Section titled “listener”Callable<TlsServerEvents[K]>
The callback to remove.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”wait()
Section titled “wait()”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.
Type Parameters
Section titled “Type Parameters”K extends "connection" | "drop" | keyof StreamServerEvents | "keylog" | "secureConnection" | "tlsClientError"
Parameters
Section titled “Parameters”K
The event name to wait for.
options?
Section titled “options?”EventDispatcherWaitOptions<TlsServerEvents[K]>
Optional settings including predicate and abort signal.
Returns
Section titled “Returns”Promise<TlsServerEvents[K]>
A promise that resolves with the event arguments as an array.
Inherited from
Section titled “Inherited from”from()
Section titled “from()”
staticfrom(options?):TlsServer
Defined in: packages/node/src/net/tls-server.ts:60
Creates a new TlsServer instance.
Parameters
Section titled “Parameters”options?
Section titled “options?”TlsOptions
Options for creating the underlying Node.js server, including the certificate chain and private key to serve.
Returns
Section titled “Returns”TlsServer
A new TlsServer instance.