Skip to content
VaelJS Blog

node:tls

Node-compatible TLS/SSL encrypted sockets, servers, and certificate utilities (node:tls).

Available in vjs only (not available in vjs-lite). Enabled by default unless --no-node-compat is passed.

import ... from "node:tls"
Since v0.0.0-alpha.2 vjs (V8)
Cargo feature: node-compat (enabled by default in vjs; absent in vjs-lite; disable with --no-node-compat)
import { DEFAULT_MIN_VERSION, getCiphers } from "node:tls";
console.log(DEFAULT_MIN_VERSION, getCiphers().length);
API Symbols
functionSince v0.0.0-alpha.2vjs only
export function checkServerIdentity(hostname: string, cert: PeerCertificate): Error | undefined;

Verify that cert is valid for hostname according to RFC 6125 / SAN rules.

Parameters
NameTypeDescription
hostnamestringExpected server hostname or IP address.
certPeerCertificatePeer certificate metadata to verify.
Returns
Error | undefined — undefined when valid, or an Error describing the mismatch.
functionSince v0.0.0-alpha.2vjs only
export function connect(
  options: ConnectionOptions,
  secureConnectListener?: () => void,
): TLSSocket;
export function connect(
  port: number,
  host?: string,
  options?: ConnectionOptions,
  secureConnectListener?: () => void,
): TLSSocket;
export function connect(
  port: number,
  options?: ConnectionOptions,
  secureConnectListener?: () => void,
): TLSSocket;

Open an encrypted TLS client connection using options.

Overload 1 — connect(options, secureConnectListener?)
NameTypeDescription
optionsConnectionOptionsTLS connection options.
secureConnectListener optional() => voidOptional "secureConnect" listener.
TLSSocket — Connected TLSSocket.
Overload 2 — connect(port, host?, options?, secureConnectListener?)

Open an encrypted TLS client connection to port and optional host.

NameTypeDescription
portnumberRemote TCP port.
host optionalstringRemote hostname or IP address.
options optionalConnectionOptionsOptional TLS connection options.
secureConnectListener optional() => voidOptional "secureConnect" listener.
TLSSocket — Connected TLSSocket.
Overload 3 — connect(port, options?, secureConnectListener?)

Open an encrypted TLS client connection to port on localhost with options.

NameTypeDescription
portnumberRemote TCP port.
options optionalConnectionOptionsOptional TLS connection options.
secureConnectListener optional() => voidOptional "secureConnect" listener.
TLSSocket — Connected TLSSocket.
functionSince v0.0.0-alpha.2vjs only
export function createSecureContext(options?: SecureContextOptions): SecureContext;

Create a reusable SecureContext from PEM certificates, keys, and TLS policy.

Parameters
NameTypeDescription
options optionalSecureContextOptionsSecure context configuration.
Returns
SecureContext — Initialized SecureContext.
functionSince v0.0.0-alpha.2vjs only
export function createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server;
export function createServer(
  options: TlsOptions,
  secureConnectionListener?: (socket: TLSSocket) => void,
): Server;

Create a new TLS Server.

Overload 1 — createServer(secureConnectionListener?)
NameTypeDescription
secureConnectionListener optional(socket: TLSSocket) => voidOptional "secureConnection" listener.
Server — New tls.Server instance.
Overload 2 — createServer(options, secureConnectionListener?)

Create a new TLS Server with explicit options.

NameTypeDescription
optionsTlsOptionsTLS server configuration.
secureConnectionListener optional(socket: TLSSocket) => voidOptional "secureConnection" listener.
Server — New tls.Server instance.
functionSince v0.0.0-alpha.2vjs only
export function getCiphers(): string[];

Return the list of supported TLS cipher suite names in lowercase.

Returns
string[] — Array of cipher suite names.
classSince v0.0.0-alpha.2vjs only
export class TLSSocket {
  readonly encrypted: boolean;
  readonly authorized: boolean;
  readonly authorizationError?: Error;
  readonly alpnProtocol: string | false | null;
  readonly servername?: string | false;
  readonly localAddress?: string;
  readonly localPort?: number;
  readonly remoteAddress?: string;
  readonly remotePort?: number;
  readonly destroyed: boolean;
  readonly readable: boolean;
  readonly writable: boolean;
  constructor(socket: unknown, options?: TLSSocketOptions);
  getPeerCertificate(detailed: true): DetailedPeerCertificate;
  getPeerCertificate(detailed?: false): PeerCertificate;
  getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
  getCipher(): CipherNameAndProtocol;
  getProtocol(): string | null;
  getSession(): Uint8Array | undefined;
  renegotiate(
      options: { rejectUnauthorized?: boolean; requestCert?: boolean },
      callback: (err: Error | null) => void,
    ): boolean | undefined;
  setMaxSendFragment(size: number): boolean;
  setTimeout(timeout: number, callback?: () => void): this;
  write(chunk: string | Uint8Array, callback?: (err?: Error | null) => void): boolean;
  write(chunk: string, encoding: string, callback?: (err?: Error | null) => void): boolean;
  end(callback?: () => void): this;
  end(chunk: string | Uint8Array, callback?: () => void): this;
  destroy(error?: Error): this;
  pause(): this;
  resume(): this;
  setEncoding(encoding?: string): this;
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
  once(eventName: string | symbol, listener: (...args: any[]) => void): this;
  off(eventName: string | symbol, listener: (...args: any[]) => void): this;
  emit(eventName: string | symbol, ...args: any[]): boolean;
  [Symbol.asyncIterator](): AsyncIterableIterator<any>;
}

Encrypted duplex TLS socket wrapping a TCP or duplex stream.

Constructor
constructor(socket: unknown, options?: TLSSocketOptions);

Wrap an existing stream or socket in TLS encryption.

Parameters
NameTypeDescription
socketunknownUnderlying TCP socket or duplex stream.
options optionalTLSSocketOptionsOptional TLS socket configuration.
Properties
PropertyTypeDescriptionSince
encrypted readonlybooleanAlways true for a TLSSocket.v0.0.0-alpha.2
authorized readonlybooleantrue if the peer certificate passed verification.v0.0.0-alpha.2
authorizationError readonly optionalErrorError describing why peer verification failed, if unauthorized.v0.0.0-alpha.2
alpnProtocol readonlystring | false | nullNegotiated ALPN protocol string, false, or null.v0.0.0-alpha.2
servername readonly optionalstring | falseRequested SNI server name, if present.v0.0.0-alpha.2
localAddress readonly optionalstringBound local IP address.v0.0.0-alpha.2
localPort readonly optionalnumberBound local port.v0.0.0-alpha.2
remoteAddress readonly optionalstringRemote peer IP address.v0.0.0-alpha.2
remotePort readonly optionalnumberRemote peer port.v0.0.0-alpha.2
destroyed readonlybooleanWhether destroy() has been called.v0.0.0-alpha.2
readable readonlybooleanWhether the socket is readable.v0.0.0-alpha.2
writable readonlybooleanWhether the socket is writable.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
getPeerCertificate(detailed: true): DetailedPeerCertificate;
getPeerCertificate(detailed?: false): PeerCertificate;
getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;

Return the peer certificate object (or {} if none).

Return the peer certificate object.

Parameters
NameTypeDescription
detailed optionaltrue | false | boolean—
methodSince v0.0.0-alpha.2
getCipher(): CipherNameAndProtocol;

Return negotiated cipher suite and TLS version details.

methodSince v0.0.0-alpha.2
getProtocol(): string | null;

Return the negotiated TLS protocol string (for example "TLSv1.3"), or null.

Returns
string | null
methodSince v0.0.0-alpha.2
getSession(): Uint8Array | undefined;

Return serialized TLS session data, if available.

Returns
Uint8Array | undefined
methodSince v0.0.0-alpha.2
renegotiate(
  options: { rejectUnauthorized?: boolean; requestCert?: boolean },
  callback: (err: Error | null) => void,
): boolean | undefined;

Initiate TLS renegotiation where supported.

Parameters
NameTypeDescription
options{ rejectUnauthorized?: boolean; requestCert?: boolean }—
callback(err: Error | null) => void—
Returns
boolean | undefined
methodSince v0.0.0-alpha.2
setMaxSendFragment(size: number): boolean;

Configure maximum plaintext fragment size per TLS record.

Parameters
NameTypeDescription
sizenumber—
Returns
boolean
methodSince v0.0.0-alpha.2
setTimeout(timeout: number, callback?: () => void): this;

Set socket inactivity timeout in milliseconds.

Parameters
NameTypeDescription
timeoutnumber—
callback optional() => void—
Returns
this
methodSince v0.0.0-alpha.2
write(chunk: string | Uint8Array, callback?: (err?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (err?: Error | null) => void): boolean;

Write encrypted data to the socket.

Overload 1 — write(chunk, callback?)
NameTypeDescription
chunkstring | Uint8Array—
callback optional(err?: Error | null) => void—
boolean
Overload 2 — write(chunk, encoding, callback?)

Write string data with encoding to the socket.

NameTypeDescription
chunkstring—
encodingstring—
callback optional(err?: Error | null) => void—
boolean
methodSince v0.0.0-alpha.2
end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;

Half-close the TLS socket.

Overload 1 — end(callback?)
NameTypeDescription
callback optional() => void—
this
Overload 2 — end(chunk, callback?)

Write a final chunk and half-close the TLS socket.

NameTypeDescription
chunkstring | Uint8Array—
callback optional() => void—
this
methodSince v0.0.0-alpha.2
destroy(error?: Error): this;

Destroy the TLS socket immediately.

Parameters
NameTypeDescription
error optionalError—
Returns
this
methodSince v0.0.0-alpha.2
pause(): this;

Pause "data" event emission.

Returns
this
methodSince v0.0.0-alpha.2
resume(): this;

Resume "data" event emission.

Returns
this
methodSince v0.0.0-alpha.2
setEncoding(encoding?: string): this;

Set encoding for decoded "data" chunks.

Parameters
NameTypeDescription
encoding optionalstring—
Returns
this
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register an event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove an event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
emit(eventName: string | symbol, ...args: any[]): boolean;

Synchronously emit an event.

Parameters
NameTypeDescription
eventNamestring | symbol—
...argsany[]—
Returns
boolean
methodSince v0.0.0-alpha.2
[Symbol.asyncIterator](): AsyncIterableIterator<any>;

Iterate asynchronously over decrypted chunks.

classSince v0.0.0-alpha.2vjs only
export class Server {
  readonly listening: boolean;
  constructor(secureConnectionListener?: (socket: TLSSocket) => void);
  constructor(
      options: TlsOptions,
      secureConnectionListener?: (socket: TLSSocket) => void,
    );
  listen(port?: number, hostname?: string, listeningListener?: () => void): this;
  listen(port?: number, listeningListener?: () => void): this;
  listen(options: { port?: number; host?: string; backlog?: number; path?: string }, listeningListener?: () => void): this;
  close(callback?: (err?: Error) => void): this;
  address(): { address: string; family: string; port: number } | string | null;
  addContext(hostname: string, context: SecureContextOptions): void;
  setSecureContext(options: SecureContextOptions): void;
  getTicketKeys(): Uint8Array;
  setTicketKeys(keys: Uint8Array): void;
  ref(): this;
  unref(): this;
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
  once(eventName: string | symbol, listener: (...args: any[]) => void): this;
  off(eventName: string | symbol, listener: (...args: any[]) => void): this;
  emit(eventName: string | symbol, ...args: any[]): boolean;
  [Symbol.asyncDispose](): Promise<void>;
}

TLS-enabled TCP server accepting inbound TLSSocket connections.

Constructor
constructor(secureConnectionListener?: (socket: TLSSocket) => void);
constructor(
  options: TlsOptions,
  secureConnectionListener?: (socket: TLSSocket) => void,
);

Construct a tls.Server with an optional "secureConnection" listener.

Overload 1 — new Server(secureConnectionListener?)
NameTypeDescription
secureConnectionListener optional(socket: TLSSocket) => voidCallback invoked with each authenticated TLSSocket.
Overload 2 — new Server(options, secureConnectionListener?)

Construct a tls.Server with explicit options and optional listener.

NameTypeDescription
optionsTlsOptionsTLS server certificates and handshake options.
secureConnectionListener optional(socket: TLSSocket) => voidCallback invoked with each authenticated TLSSocket.
Properties
PropertyTypeDescriptionSince
listening readonlybooleantrue while the server is listening.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(options: { port?: number; host?: string; backlog?: number; path?: string }, listeningListener?: () => void): this;

Start listening for TLS connections on port.

Overload 1 — listen(port?, hostname?, listeningListener?)
NameTypeDescription
port optionalnumber—
hostname optionalstring—
listeningListener optional() => void—
this
Overload 2 — listen(port?, listeningListener?)

Start listening on port with optional listener.

NameTypeDescription
port optionalnumber—
listeningListener optional() => void—
this
Overload 3 — listen(options, listeningListener?)

Start listening using explicit options.

NameTypeDescription
options{ port?: number; host?: string; backlog?: number; path?: string }—
listeningListener optional() => void—
this
methodSince v0.0.0-alpha.2
close(callback?: (err?: Error) => void): this;

Stop accepting new TLS connections.

Parameters
NameTypeDescription
callback optional(err?: Error) => void—
Returns
this
methodSince v0.0.0-alpha.2
address(): { address: string; family: string; port: number } | string | null;

Return bound local address metadata or null.

Returns
{ address: string; family: string; port: number } | string | null
methodSince v0.0.0-alpha.2
addContext(hostname: string, context: SecureContextOptions): void;

Register an SNI hostname-specific SecureContextOptions.

Parameters
NameTypeDescription
hostnamestring—
contextSecureContextOptions—
Returns
void
methodSince v0.0.0-alpha.2
setSecureContext(options: SecureContextOptions): void;

Replace the server’s default TLS credentials and options.

Parameters
NameTypeDescription
optionsSecureContextOptions—
Returns
void
methodSince v0.0.0-alpha.2
getTicketKeys(): Uint8Array;

Return the current 48-byte TLS session ticket keys.

Returns
methodSince v0.0.0-alpha.2
setTicketKeys(keys: Uint8Array): void;

Replace the 48-byte TLS session ticket keys.

Parameters
NameTypeDescription
keysUint8Array—
Returns
void
methodSince v0.0.0-alpha.2
ref(): this;

Keep the event loop active while listening.

Returns
this
methodSince v0.0.0-alpha.2
unref(): this;

Allow the event loop to exit if the server is the only active handle.

Returns
this
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register an event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove an event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
emit(eventName: string | symbol, ...args: any[]): boolean;

Synchronously emit an event.

Parameters
NameTypeDescription
eventNamestring | symbol—
...argsany[]—
Returns
boolean
methodSince v0.0.0-alpha.2
[Symbol.asyncDispose](): Promise<void>;

Close the server asynchronously when disposed via await using.

Returns
Promise<void>
interfaceSince v0.0.0-alpha.2vjs only
export interface PeerCertificate {
  subject: Record<string, string | string[]>;
  issuer: Record<string, string | string[]>;
  subjectaltname?: string;
  infoAccess?: Record<string, string[]>;
  valid_from: string;
  valid_to: string;
  fingerprint: string;
  fingerprint256: string;
  fingerprint512?: string;
  serialNumber: string;
  raw: Uint8Array;
}

Decoded X.509 certificate metadata returned by TLSSocket.getPeerCertificate().

Properties
PropertyTypeDescriptionSince
subject Record<string, string | string[]>Certificate subject distinguished-name fields.v0.0.0-alpha.2
issuer Record<string, string | string[]>Certificate issuer distinguished-name fields.v0.0.0-alpha.2
subjectaltname optionalstringComma-separated Subject Alternative Name entries.v0.0.0-alpha.2
infoAccess optionalRecord<string, string[]>Authority Information Access URIs keyed by extension name.v0.0.0-alpha.2
valid_from stringValidity start date string.v0.0.0-alpha.2
valid_to stringValidity expiration date string.v0.0.0-alpha.2
fingerprint stringSHA-1 fingerprint string.v0.0.0-alpha.2
fingerprint256 stringSHA-256 fingerprint string.v0.0.0-alpha.2
fingerprint512 optionalstringSHA-512 fingerprint string.v0.0.0-alpha.2
serialNumber stringHexadecimal certificate serial number.v0.0.0-alpha.2
raw Uint8ArrayRaw DER-encoded certificate bytes.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface DetailedPeerCertificate extends PeerCertificate {
  issuerCertificate: DetailedPeerCertificate;
}

Peer certificate including the issuing certificate chain when detailed: true.

Properties
PropertyTypeDescriptionSince
issuerCertificate DetailedPeerCertificateIssuing CA certificate in the verified chain.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface CipherNameAndProtocol {
  name: string;
  standardName: string;
  version: string;
}

Negotiated TLS cipher suite and protocol details.

Properties
PropertyTypeDescriptionSince
name stringOpenSSL-style cipher suite name.v0.0.0-alpha.2
standardName stringIANA standard cipher suite name.v0.0.0-alpha.2
version stringNegotiated TLS protocol version string.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface SecureContext {
  context: unknown;
}

Opaque secure context object created by createSecureContext().

Properties
PropertyTypeDescriptionSince
context unknownInternal secure context handle.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface SecureContextOptions {
  ca?: string | Uint8Array | Array<string | Uint8Array>;
  cert?: string | Uint8Array | Array<string | Uint8Array>;
  key?:
      | string
      | Uint8Array
      | Array<string | Uint8Array | { pem: string | Uint8Array; passphrase?: string }>;
  passphrase?: string;
  pfx?:
      | string
      | Uint8Array
      | Array<string | Uint8Array | { buf: string | Uint8Array; passphrase?: string }>;
  ciphers?: string;
  ecdhCurve?: string;
  minVersion?: SecureVersion;
  maxVersion?: SecureVersion;
  secureProtocol?: string;
  honorCipherOrder?: boolean;
  ALPNProtocols?: string[] | Uint8Array[] | Uint8Array;
  sessionTimeout?: number;
  ticketKeys?: Uint8Array;
  crl?: string | Uint8Array | Array<string | Uint8Array>;
  dhparam?: string | Uint8Array;
  sigalgs?: string;
}

Options accepted by createSecureContext().

Properties
PropertyTypeDescriptionSince
ca optionalstring | Uint8Array | Array<string | Uint8Array>Trusted CA certificates (PEM string or bytes).v0.0.0-alpha.2
cert optionalstring | Uint8Array | Array<string | Uint8Array>Certificate chain(s) in PEM format.v0.0.0-alpha.2
key optional| string | Uint8Array | Array<string | Uint8Array | { pem: string | Uint8Array; passphrase?: string }>Private key(s) in PEM format.v0.0.0-alpha.2
passphrase optionalstringPassphrase protecting encrypted private keys or PKCS#12 bundles.v0.0.0-alpha.2
pfx optional| string | Uint8Array | Array<string | Uint8Array | { buf: string | Uint8Array; passphrase?: string }>PKCS#12 certificate/key bundle(s).v0.0.0-alpha.2
ciphers optionalstringCipher suite specification string.v0.0.0-alpha.2
ecdhCurve optionalstringNamed ECDH curve(s).v0.0.0-alpha.2
minVersion optionalSecureVersionMinimum allowed TLS version.v0.0.0-alpha.2
maxVersion optionalSecureVersionMaximum allowed TLS version.v0.0.0-alpha.2
secureProtocol optionalstringLegacy SSL/TLS method identifier.v0.0.0-alpha.2
honorCipherOrder optionalbooleanPrefer server cipher order when negotiating.v0.0.0-alpha.2
ALPNProtocols optionalstring[] | Uint8Array[] | Uint8ArrayAdvertised ALPN protocol names.v0.0.0-alpha.2
sessionTimeout optionalnumberTLS session timeout in seconds.v0.0.0-alpha.2
ticketKeys optionalUint8Array48-byte TLS session ticket encryption keys.v0.0.0-alpha.2
crl optionalstring | Uint8Array | Array<string | Uint8Array>Certificate revocation list(s) in PEM format.v0.0.0-alpha.2
dhparam optionalstring | Uint8ArrayDiffie-Hellman parameters in PEM format.v0.0.0-alpha.2
sigalgs optionalstringSupported signature algorithms list.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface TLSSocketOptions extends SecureContextOptions {
  isServer?: boolean;
  server?: Server;
  requestCert?: boolean;
  rejectUnauthorized?: boolean;
  SNICallback?: (
      servername: string,
      cb: (err: Error | null, ctx?: SecureContext) => void,
    ) => void;
  session?: Uint8Array;
  requestOCSP?: boolean;
  secureContext?: SecureContext;
}

Options accepted by new TLSSocket(socket, options).

Properties
PropertyTypeDescriptionSince
isServer optionalbooleanConfigure socket in TLS server mode when true.v0.0.0-alpha.2
server optionalServerOwning TLS server instance, if applicable.v0.0.0-alpha.2
requestCert optionalbooleanRequest a client certificate during handshake.v0.0.0-alpha.2
rejectUnauthorized optionalbooleanReject peers whose certificate fails trust verification (default true).v0.0.0-alpha.2
SNICallback optional( servername: string, cb: (err: Error | null, ctx?: SecureContext) => void, ) => voidCallback selecting a SecureContext dynamically from SNI servername.v0.0.0-alpha.2
session optionalUint8ArrayResumable TLS session bytes.v0.0.0-alpha.2
requestOCSP optionalbooleanRequest OCSP stapling response from peer.v0.0.0-alpha.2
secureContext optionalSecureContextPre-built SecureContext instance.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface TlsOptions extends SecureContextOptions {
  handshakeTimeout?: number;
  requestCert?: boolean;
  rejectUnauthorized?: boolean;
  SNICallback?: (
      servername: string,
      cb: (err: Error | null, ctx?: SecureContext) => void,
    ) => void;
  noDelay?: boolean;
  keepAlive?: boolean;
  allowHalfOpen?: boolean;
  pauseOnConnect?: boolean;
  secureContext?: SecureContext;
}

Options accepted by createServer() and new Server().

Properties
PropertyTypeDescriptionSince
handshakeTimeout optionalnumberTLS handshake timeout in milliseconds.v0.0.0-alpha.2
requestCert optionalbooleanRequest client certificate authentication.v0.0.0-alpha.2
rejectUnauthorized optionalbooleanReject clients without valid certificates (default true when requestCert is set).v0.0.0-alpha.2
SNICallback optional( servername: string, cb: (err: Error | null, ctx?: SecureContext) => void, ) => voidCallback selecting a SecureContext dynamically from SNI servername.v0.0.0-alpha.2
noDelay optionalbooleanDisable Nagle's algorithm (TCP_NODELAY).v0.0.0-alpha.2
keepAlive optionalbooleanEnable TCP keep-alive probes.v0.0.0-alpha.2
allowHalfOpen optionalbooleanAllow half-open TCP sockets.v0.0.0-alpha.2
pauseOnConnect optionalbooleanPause accepted sockets before emitting "secureConnection".v0.0.0-alpha.2
secureContext optionalSecureContextPre-built SecureContext instance.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface ConnectionOptions extends SecureContextOptions {
  host?: string;
  port?: number;
  path?: string;
  servername?: string;
  checkServerIdentity?: typeof checkServerIdentity;
  rejectUnauthorized?: boolean;
  timeout?: number;
  socket?: unknown;
  secureContext?: SecureContext;
  session?: Uint8Array;
}

Options accepted by tls.connect().

Properties
PropertyTypeDescriptionSince
host optionalstringRemote hostname or IP address (default "localhost").v0.0.0-alpha.2
port optionalnumberRemote TCP port (0..=65535).v0.0.0-alpha.2
path optionalstringUnix socket or named pipe path.v0.0.0-alpha.2
servername optionalstringSNI server name for certificate verification.v0.0.0-alpha.2
checkServerIdentity optionaltypeof checkServerIdentityCustom hostname/certificate verification callback.v0.0.0-alpha.2
rejectUnauthorized optionalbooleanReject servers with invalid certificates (default true).v0.0.0-alpha.2
timeout optionalnumberSocket inactivity timeout in milliseconds.v0.0.0-alpha.2
socket optionalunknownExisting duplex socket to wrap with TLS.v0.0.0-alpha.2
secureContext optionalSecureContextPre-built SecureContext instance.v0.0.0-alpha.2
session optionalUint8ArrayResumable TLS session bytes.v0.0.0-alpha.2
typeSince v0.0.0-alpha.2vjs only
export type SecureVersion = "TLSv1.3" | "TLSv1.2" | "TLSv1.1" | "TLSv1";

Supported TLS protocol version identifiers.

constSince v0.0.0-alpha.2vjs only
export const DEFAULT_CIPHERS: string;

Default cipher suite specification string.

constSince v0.0.0-alpha.2vjs only
export const DEFAULT_ECDH_CURVE: string;

Default ECDH curve name.

constSince v0.0.0-alpha.2vjs only
export const DEFAULT_MAX_VERSION: SecureVersion;

Default maximum supported TLS version.

constSince v0.0.0-alpha.2vjs only
export const DEFAULT_MIN_VERSION: SecureVersion;

Default minimum supported TLS version.

constSince v0.0.0-alpha.2vjs only
export const rootCertificates: readonly string[];

Bundled PEM-encoded root CA certificates trusted by default.

defaultSince v0.0.0-alpha.2vjs only
const _default: {
  /** Default cipher string. @since 0.0.0-alpha.2 */
  readonly DEFAULT_CIPHERS: string;
  /** Default ECDH curve. @since 0.0.0-alpha.2 */
  readonly DEFAULT_ECDH_CURVE: string;
  /** Default maximum TLS version. @since 0.0.0-alpha.2 */
  readonly DEFAULT_MAX_VERSION: SecureVersion;
  /** Default minimum TLS version. @since 0.0.0-alpha.2 */
  readonly DEFAULT_MIN_VERSION: SecureVersion;
  /** `Server` constructor. @since 0.0.0-alpha.2 */
  Server: typeof Server;
  /** `TLSSocket` constructor. @since 0.0.0-alpha.2 */
  TLSSocket: typeof TLSSocket;
  /** Verify certificate SAN/CN against hostname. @since 0.0.0-alpha.2 */
  checkServerIdentity: typeof checkServerIdentity;
  /** Open a TLS client connection. @since 0.0.0-alpha.2 */
  connect: typeof connect;
  /** Create a `SecureContext`. @since 0.0.0-alpha.2 */
  createSecureContext: typeof createSecureContext;
  /** Create a TLS server. @since 0.0.0-alpha.2 */
  createServer: typeof createServer;
  /** Return supported cipher suite names. @since 0.0.0-alpha.2 */
  getCiphers: typeof getCiphers;
  /** Bundled root CA certificates. @since 0.0.0-alpha.2 */
  readonly rootCertificates: readonly string[];
};
export default _default;

Default export object providing the node:tls API.