Spec-Zone.ru › Deno 2

Network

A wide range of networking tasks, from low-level connections to high-level server creation. Handle HTTP requests, WebSocket communication, and DNS resolution. Useful for building web servers, clients, and networking tools.

Eg Deno.connect, Deno.listen, Deno.resolveDns


class Deno.QuicEndpoint

unstable

Constructors

QuicEndpoint(options?: QuicEndpointOptions)
new

Create a QUIC endpoint which may be used for client or server connections.

Requires allow-net permission.

Properties

addr: NetAddr
readonly

Return the address of the QuicListener.

Methods

close(info?: QuicCloseInfo): void

Closes the endpoint. All associated connections will be closed and incoming connections will be rejected.

listen(options: QuicListenOptions): QuicListener

Listen announces on the local transport address over QUIC.


function Deno.connect

unstable
allow-net allow-read

Overload 1

connect(options: ConnectOptions): Promise<TcpConn>

Connects to the hostname (default is "127.0.0.1") and port on the named transport (default is "tcp"), and resolves to the connection (Conn).

const conn1 = await Deno.connect({ port: 80 });
const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });

Requires allow-net permission for "tcp".

Parameters

options: ConnectOptions

Return Type

Promise<TcpConn>

Overload 2

connect(options: UnixConnectOptions): Promise<UnixConn>

Connects to the hostname (default is "127.0.0.1") and port on the named transport (default is "tcp"), and resolves to the connection (Conn).

const conn1 = await Deno.connect({ port: 80 });
const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" });

Requires allow-net permission for "tcp", and allow-read and allow-net for "unix". The "unix" allow-net grant may be scoped to the socket path with --allow-net=unix:<absolute-path>.

Parameters

options: UnixConnectOptions

Return Type

Promise<UnixConn>

Overload 3

connect(options: VsockConnectOptions): Promise<VsockConn>

Connects to the hostname (default is "127.0.0.1") and port on the named transport (default is "tcp"), and resolves to the connection (Conn).

Parameters

options: VsockConnectOptions

Return Type

Promise<VsockConn>

function Deno.connectQuic

unstable
allow-net
connectQuic<ZRTT extends boolean>(options: ConnectQuicOptions<ZRTT>): ZRTT extends true ? (QuicConn | Promise<QuicConn>) : Promise<QuicConn>

Establishes a secure connection over QUIC using a hostname and port. The cert file is optional and if not included Mozilla's root certificates will be used. See also https://github.com/ctz/webpki-roots for specifics.

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
const conn1 = await Deno.connectQuic({ hostname: "example.com", port: 443, alpnProtocols: ["h3"] });
const conn2 = await Deno.connectQuic({ caCerts: [caCert], hostname: "example.com", port: 443, alpnProtocols: ["h3"] });

If an endpoint is shared among many connections, 0-RTT can be enabled. When 0-RTT is successful, a QuicConn will be synchronously returned and data can be sent immediately with it. Any data sent before the TLS handshake completes is vulnerable to replay attacks.

Requires allow-net permission.

Type Parameters

ZRTT extends boolean

Parameters

options: ConnectQuicOptions<ZRTT>

Return Type

ZRTT extends true ? (QuicConn | Promise<QuicConn>) : Promise<QuicConn>

function Deno.connectTls

allow-net
connectTls(options: ConnectTlsOptions | (ConnectTlsOptions & TlsCertifiedKeyPem)): Promise<TlsConn>

Establishes a secure connection over TLS (transport layer security) using an optional list of CA certs, hostname (default is "127.0.0.1") and port.

The CA cert list is optional and if not included Mozilla's root certificates will be used (see also https://github.com/ctz/webpki-roots for specifics).

Mutual TLS (mTLS or client certificates) are supported by providing a key and cert in the options as PEM-encoded strings.

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
const conn1 = await Deno.connectTls({ port: 80 });
const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "192.0.2.1", port: 80 });
const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 });
const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "golang.org", port: 80});

const key = "----BEGIN PRIVATE KEY----...";
const cert = "----BEGIN CERTIFICATE----...";
const conn5 = await Deno.connectTls({ port: 80, key, cert });

Requires allow-net permission.

Parameters

options: ConnectTlsOptions | (ConnectTlsOptions & TlsCertifiedKeyPem)

Return Type

Promise<TlsConn>

function Deno.listen

unstable
allow-net allow-read allow-write

Overload 1

listen(options: TcpListenOptions & { transport?: "tcp"; }): TcpListener

Listen announces on the local transport address.

const listener1 = Deno.listen({ port: 80 })
const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 })
const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 });
const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" });

Requires allow-net permission.

Parameters

options: TcpListenOptions & { transport?: "tcp"; }

Return Type

TcpListener

Overload 2

listen(options: UnixListenOptions & { transport: "unix"; }): UnixListener

Listen announces on the local transport address.

const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" })

Requires allow-read, allow-write and allow-net permission. The allow-net grant may be scoped to the socket path with --allow-net=unix:<absolute-path>.

Parameters

options: UnixListenOptions & { transport: "unix"; }

Return Type

UnixListener

Overload 3

listen(options: VsockListenOptions & { transport: "vsock"; }): VsockListener

Listen announces on the local transport address.

Parameters

options: VsockListenOptions & { transport: "vsock"; }

Return Type

VsockListener

function Deno.listenDatagram

unstable
allow-net allow-read allow-write

Overload 1

listenDatagram(options: UdpListenOptions & { transport: "udp"; }): DatagramConn

Listen announces on the local transport address.

const listener1 = Deno.listenDatagram({
  port: 80,
  transport: "udp"
});
const listener2 = Deno.listenDatagram({
  hostname: "golang.org",
  port: 80,
  transport: "udp"
});

Requires allow-net permission.

Parameters

options: UdpListenOptions & { transport: "udp"; }

Return Type

DatagramConn

Overload 2

listenDatagram(options: UnixListenDatagramOptions & { transport: "unixpacket"; }): DatagramConn

Listen announces on the local transport address.

const listener = Deno.listenDatagram({
  path: "/foo/bar.sock",
  transport: "unixpacket"
});

Requires allow-read, allow-write and allow-net permission. The allow-net grant may be scoped to the socket path with --allow-net=unix:<absolute-path>.

Parameters

options: UnixListenDatagramOptions & { transport: "unixpacket"; }

Return Type

DatagramConn

function Deno.listenTls

allow-net
listenTls(options: ListenTlsOptions & TlsCertifiedKeyPem): TlsListener

Listen announces on the local transport address over TLS (transport layer security).

using listener = Deno.listenTls({
  port: 443,
  cert: Deno.readTextFileSync("./server.crt"),
  key: Deno.readTextFileSync("./server.key"),
});

Requires allow-net permission.

Parameters

options: ListenTlsOptions & TlsCertifiedKeyPem

Return Type

TlsListener

function Deno.networkInterfaces

allow-sys
networkInterfaces(): NetworkInterfaceInfo[]

Returns an array of the network interface information.

console.log(Deno.networkInterfaces());

Requires allow-sys permission.

Return Type

NetworkInterfaceInfo[]

function Deno.resolveDns

allow-net

Overload 1

resolveDns(
query: string,
recordType:
"A"
| "AAAA"
| "ANAME"
| "CNAME"
| "NS"
| "PTR"
,
options?: ResolveDnsOptions,
): Promise<string[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "A", "AAAA", "ANAME", "CNAME", "NS" and "PTR" record types resolve to an array of strings.

const a = await Deno.resolveDns("example.com", "A");
// ["93.184.215.14"]

const aaaa = await Deno.resolveDns("example.com", "AAAA", {
  nameServer: { ipAddr: "8.8.8.8", port: 53 },
});
// ["2606:2800:21f:cb07:6820:80da:af6b:8b2c"]

Requires allow-net permission.

Parameters

query: string
recordType:
"A"
| "AAAA"
| "ANAME"
| "CNAME"
| "NS"
| "PTR"
options: ResolveDnsOptions
optional

Return Type

Promise<string[]>

Overload 2

resolveDns(
query: string,
recordType: "CAA",
options?: ResolveDnsOptions,
): Promise<CaaRecord[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "CAA" record type resolves to an array of Deno.CaaRecord objects.

const caa = await Deno.resolveDns("example.com", "CAA");
// [{ critical: false, tag: "issue", value: "letsencrypt.org" }]

Requires allow-net permission.

Parameters

query: string
recordType: "CAA"
options: ResolveDnsOptions
optional

Return Type

Promise<CaaRecord[]>

Overload 3

resolveDns(
query: string,
recordType: "MX",
options?: ResolveDnsOptions,
): Promise<MxRecord[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "MX" record type resolves to an array of Deno.MxRecord objects.

const mx = await Deno.resolveDns("example.com", "MX");
// [{ preference: 10, exchange: "mail.example.com" }]

Requires allow-net permission.

Parameters

query: string
recordType: "MX"
options: ResolveDnsOptions
optional

Return Type

Promise<MxRecord[]>

Overload 4

resolveDns(
query: string,
recordType: "NAPTR",
options?: ResolveDnsOptions,
): Promise<NaptrRecord[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "NAPTR" record type resolves to an array of Deno.NaptrRecord objects.

const naptr = await Deno.resolveDns("example.com", "NAPTR");
// [{
//   order: 100,
//   preference: 10,
//   flags: "S",
//   services: "SIP+D2U",
//   regexp: "",
//   replacement: "_sip._udp.example.com",
// }]

Requires allow-net permission.

Parameters

query: string
recordType: "NAPTR"
options: ResolveDnsOptions
optional

Return Type

Promise<NaptrRecord[]>

Overload 5

resolveDns(
query: string,
recordType: "SOA",
options?: ResolveDnsOptions,
): Promise<SoaRecord[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "SOA" record type resolves to an array of Deno.SoaRecord objects.

const soa = await Deno.resolveDns("example.com", "SOA");
// [{
//   mname: "ns.example.com",
//   rname: "hostmaster.example.com",
//   serial: 2024010101,
//   refresh: 7200,
//   retry: 3600,
//   expire: 1209600,
//   minimum: 3600,
// }]

Requires allow-net permission.

Parameters

query: string
recordType: "SOA"
options: ResolveDnsOptions
optional

Return Type

Promise<SoaRecord[]>

Overload 6

resolveDns(
query: string,
recordType: "SRV",
options?: ResolveDnsOptions,
): Promise<SrvRecord[]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "SRV" record type resolves to an array of Deno.SrvRecord objects.

const srv = await Deno.resolveDns("_sip._tcp.example.com", "SRV");
// [{ priority: 10, weight: 5, port: 5060, target: "sip.example.com" }]

Requires allow-net permission.

Parameters

query: string
recordType: "SRV"
options: ResolveDnsOptions
optional

Return Type

Promise<SrvRecord[]>

Overload 7

resolveDns(
query: string,
recordType: "TXT",
options?: ResolveDnsOptions,
): Promise<string[][]>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

The "TXT" record type resolves to an array of string arrays, since a single TXT record can be split into multiple character strings.

const txt = await Deno.resolveDns("example.com", "TXT");
// [["v=spf1 include:_spf.example.com ~all"]]

Requires allow-net permission.

Parameters

query: string
recordType: "TXT"
options: ResolveDnsOptions
optional

Return Type

Promise<string[][]>

Overload 8

resolveDns(
query: string,
recordType: RecordType,
options?: ResolveDnsOptions,
): Promise<
string[]
| CaaRecord[]
| MxRecord[]
| NaptrRecord[]
| SoaRecord[]
| SrvRecord[]
| string[][]
>

Performs DNS resolution against the given query, returning resolved records.

Fails in the cases such as:

  • the query is in invalid format.
  • the options have an invalid parameter. For example nameServer.port is beyond the range of 16-bit unsigned integer.
  • the request timed out.

This overload is selected when the record type is only known at runtime. The shape of each resolved record depends on the Deno.RecordType that was requested - see the more specific overloads above for the exact return type of each record type.

const recordType: Deno.RecordType = "A";
const records = await Deno.resolveDns("example.com", recordType, {
  nameServer: { ipAddr: "8.8.8.8", port: 53 },
});

Requires allow-net permission.

Parameters

query: string
recordType: RecordType
options: ResolveDnsOptions
optional

Return Type

Promise<
string[]
| CaaRecord[]
| MxRecord[]
| NaptrRecord[]
| SoaRecord[]
| SrvRecord[]
| string[][]
>

function Deno.startTls

allow-net
startTls(
conn: TcpConn,
options?: StartTlsOptions,
): Promise<TlsConn>

Start TLS handshake from an existing connection using an optional list of CA certificates, and hostname (default is "127.0.0.1"). Specifying CA certs is optional. By default the configured root certificates are used. Using this function requires that the other end of the connection is prepared for a TLS handshake.

Note that this function consumes the TCP connection passed to it, thus the original TCP connection will be unusable after calling this. Additionally, you need to ensure that the TCP connection is not being used elsewhere when calling this function in order for the TCP connection to be consumed properly. For instance, if there is a Promise that is waiting for read operation on the TCP connection to complete, it is considered that the TCP connection is being used elsewhere. In such a case, this function will fail.

const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
// `conn` becomes unusable after calling `Deno.startTls`
const tlsConn = await Deno.startTls(conn, { caCerts: [caCert], hostname: "localhost" });

Requires allow-net permission.

Parameters

conn: TcpConn
options: StartTlsOptions
optional

Return Type

Promise<TlsConn>

function Deno.upgradeWebTransport

unstable
upgradeWebTransport(conn: QuicConn): Promise<WebTransport & { url: string; }>

Upgrade a QUIC connection into a WebTransport instance.

Parameters

conn: QuicConn

Return Type

Promise<WebTransport & { url: string; }>

interface Deno.CaaRecord

If Deno.resolveDns is called with "CAA" record type specified, it will resolve with an array of objects with this interface.

Properties

critical: boolean

If true, indicates that the corresponding property tag must be understood if the semantics of the CAA record are to be correctly interpreted by an issuer.

Issuers must not issue certificates for a domain if the relevant CAA Resource Record set contains unknown property tags that have critical set.

tag: string

An string that represents the identifier of the property represented by the record.

value: string

The value associated with the tag.


interface Deno.Conn

extends Disposable

A generic stream-oriented network connection that can be read from and written to.

Type Parameters

A extends Addr = Addr

Properties

localAddr: A
readonly

The local address of the connection.

remoteAddr: A
readonly

The remote address of the connection.

readable: ReadableStream<Uint8Array<ArrayBuffer>>
readonly

A ReadableStream of the data received over the connection.

writable: WritableStream<Uint8Array<ArrayBufferLike>>
readonly

A WritableStream for sending data over the connection.

Methods

read(p: Uint8Array): Promise<number | null>

Read the incoming data from the connection into an array buffer (p).

Resolves to either the number of bytes read during the operation or EOF (null) if there was nothing more to read.

It is possible for a read to successfully return with 0 bytes. This does not indicate EOF.

It is not guaranteed that the full buffer will be read in a single call.

// If the text "hello world" is received by the client:
const conn = await Deno.connect({ hostname: "example.com", port: 80 });
const buf = new Uint8Array(100);
const numberOfBytesRead = await conn.read(buf); // 11 bytes
const text = new TextDecoder().decode(buf);  // "hello world"
write(p: Uint8Array): Promise<number>

Write the contents of the array buffer (p) to the connection.

Resolves to the number of bytes written.

It is not guaranteed that the full buffer will be written in a single call.

const conn = await Deno.connect({ hostname: "example.com", port: 80 });
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
const bytesWritten = await conn.write(data); // 11
close(): void

Closes the connection, freeing the resource.

const conn = await Deno.connect({ hostname: "example.com", port: 80 });

// ...

conn.close();
closeWrite(): Promise<void>

Shuts down (shutdown(2)) the write side of the connection. Most callers should just use close().

ref(): void

Make the connection block the event loop from finishing.

Note: the connection blocks the event loop from finishing by default. This method is only meaningful after .unref() is called.

unref(): void

Make the connection not block the event loop from finishing.


interface Deno.ConnectOptions

Options which can be set when connecting via Deno.connect.

Properties

port: number

The port to connect to.

hostname: string = "127.0.0.1"
optional

A literal IP address or host name that can be resolved to an IP address. If not specified,

transport: "tcp"
optional

The transport layer protocol to use.

signal: AbortSignal
optional

An AbortSignal to close the tcp connection.

autoSelectFamily: boolean = true
optional

Enable Happy Eyeballs algorithm (RFC 8305) for automatic address family selection. When enabled, the connection will try both IPv6 and IPv4 addresses with interleaving for faster connection establishment.

autoSelectFamilyAttemptDelay: number = 250
optional

Delay in milliseconds between starting new connection attempts when using Happy Eyeballs. A new connection attempt is started every autoSelectFamilyAttemptDelay milliseconds until one succeeds.


interface Deno.ConnectQuicOptions

extends QuicTransportOptions
unstable

Type Parameters

ZRTT extends boolean

Properties

port: number

The port to connect to.

hostname: string

A literal IP address or host name that can be resolved to an IP address.

serverName: string | undefined
optional

The name used for validating the certificate provided by the server. If not provided, defaults to hostname.

alpnProtocols: string[]

Application-Layer Protocol Negotiation (ALPN) protocols supported by the client. QUIC requires the use of ALPN.

caCerts: string[]
optional

A list of root certificates that will be used in addition to the default root certificates to verify the peer's certificate.

Must be in PEM format.

endpoint: QuicEndpoint
optional

If no endpoint is provided, a new one is bound on an ephemeral port.

zeroRtt: ZRTT = false
optional

Attempt to convert the connection into 0-RTT. Any data sent before the TLS handshake completes is vulnerable to replay attacks.


interface Deno.ConnectTlsOptions

Options which can be set when establishing a TLS connection via Deno.connectTls.

Properties

port: number

The port to connect to.

hostname: string = "127.0.0.1"
optional

A literal IP address or host name that can be resolved to an IP address.

caCerts: string[]
optional

A list of root certificates that will be used in addition to the default root certificates to verify the peer's certificate.

Must be in PEM format.

alpnProtocols: string[]
optional

Application-Layer Protocol Negotiation (ALPN) protocols supported by the client. If not specified, no ALPN extension will be included in the TLS handshake.

unsafelyDisableHostnameVerification: boolean = false
optional

If true, the certificate's common name or subject alternative names will not be checked against the hostname provided in the options.

This disables hostname verification but still validates the certificate chain. Use with caution and only when connecting to known servers.

autoSelectFamily: boolean = true
optional

Enable Happy Eyeballs algorithm (RFC 8305) for automatic address family selection. When enabled, the connection will try both IPv6 and IPv4 addresses with interleaving for faster connection establishment.

autoSelectFamilyAttemptDelay: number = 250
optional

Delay in milliseconds between starting new connection attempts when using Happy Eyeballs. A new connection attempt is started every autoSelectFamilyAttemptDelay milliseconds until one succeeds.


interface Deno.DatagramConn

extends AsyncIterable<[Uint8Array<ArrayBuffer>, Addr]>
unstable

A generic transport listener for message-oriented protocols.

Properties

addr: Addr
readonly

Return the address of the instance.

Methods

joinMulticastV4(
address: string,
networkInterface: string,
): Promise<MulticastV4Membership>

Joins an IPv4 multicast group.

joinMulticastV6(
address: string,
networkInterface: number,
): Promise<MulticastV6Membership>

Joins an IPv6 multicast group.

receive(p?: Uint8Array): Promise<[Uint8Array<ArrayBuffer>, Addr]>

Waits for and resolves to the next message to the instance.

Messages are received in the format of a tuple containing the data array and the address information.

send(
p: Uint8Array,
addr: Addr,
): Promise<number>

Sends a message to the target via the connection. The method resolves with the number of bytes sent.

close(): void

Close closes the socket. Any pending message promises will be rejected with errors.

[[Symbol.asyncIterator]](): AsyncIterableIterator<[Uint8Array<ArrayBuffer>, Addr]>

interface Deno.Listener

extends AsyncIterable<T>Disposable

A generic network listener for stream-oriented protocols.

Type Parameters

T extends Conn = Conn
A extends Addr = Addr

Properties

addr: A
readonly

Return the address of the Listener.

Methods

accept(): Promise<T>

Waits for and resolves to the next connection to the Listener.

close(): void

Close closes the listener. Any pending accept promises will be rejected with errors. A pending async iterator next() call will settle after the underlying accept promise is rejected.

If the listener has a pending accept operation, the underlying socket may not be released until the pending promise is rejected. If you need to listen on the same address immediately after closing the listener, await the pending accept promise before calling Deno.listen again.

[[Symbol.asyncIterator]](): AsyncIterableIterator<T>

Iterates over the connections accepted by the listener.

ref(): void

Make the listener block the event loop from finishing.

Note: the listener blocks the event loop from finishing by default. This method is only meaningful after .unref() is called.

unref(): void

Make the listener not block the event loop from finishing.


interface Deno.ListenOptions

Options which can be set when opening a listener via Deno.listen.

Properties

port: number
optional

The port to listen on.

Set to 0 to listen on any available port.

hostname: string = "0.0.0.0"
optional

A literal IP address or host name that can be resolved to an IP address.

Note about 0.0.0.0 While listening 0.0.0.0 works on all platforms, the browsers on Windows don't work with the address 0.0.0.0. You should show the message like server running on localhost:8080 instead of server running on 0.0.0.0:8080 if your program supports Windows.

tcpBacklog: number = 511
optional

Maximum number of pending connections in the listen queue.

This parameter controls how many incoming connections can be queued by the operating system while waiting for the application to accept them. If more connections arrive when the queue is full, they will be refused.

The kernel may adjust this value (e.g., rounding up to the next power of 2 plus 1). Different operating systems have different maximum limits.


interface Deno.ListenTlsOptions

extends TcpListenOptions

Options which can be set when opening a TLS listener via Deno.listenTls.

Properties

transport: "tcp"
optional

The transport layer protocol to use.

alpnProtocols: string[]
optional

Application-Layer Protocol Negotiation (ALPN) protocols to announce to the client. If not specified, no ALPN extension will be included in the TLS handshake.


interface Deno.MulticastV4Membership

unstable

Represents membership of a IPv4 multicast group.

Properties

leave: () => Promise<void>

Leaves the multicast group.

setLoopback: (loopback: boolean) => Promise<void>

Sets the multicast loopback option. If enabled, multicast packets will be looped back to the local socket.

setTTL: (ttl: number) => Promise<void>

Sets the time-to-live of outgoing multicast packets for this socket.


interface Deno.MulticastV6Membership

unstable

Represents membership of a IPv6 multicast group.

Properties

leave: () => Promise<void>

Leaves the multicast group.

setLoopback: (loopback: boolean) => Promise<void>

Sets the multicast loopback option. If enabled, multicast packets will be looped back to the local socket.


interface Deno.MxRecord

If Deno.resolveDns is called with "MX" record type specified, it will return an array of objects with this interface.

Properties

preference: number

A priority value, which is a relative value compared to the other preferences of MX records for the domain.

exchange: string

The server that mail should be delivered to.


interface Deno.NaptrRecord

If Deno.resolveDns is called with "NAPTR" record type specified, it will return an array of objects with this interface.

Properties

order: number
preference: number
flags: string
services: string
regexp: string
replacement: string

interface Deno.NetAddr

The address of a network connection or listener using an IP-based transport.

Properties

transport: "tcp" | "udp"

The IP-based transport protocol.

hostname: string

The IP address.

port: number

The port number.


interface Deno.NetworkInterfaceInfo

The information for a network interface returned from a call to Deno.networkInterfaces.

Properties

name: string

The network interface name.

family: "IPv4" | "IPv6"

The IP protocol version.

address: string

The IP address bound to the interface.

netmask: string

The netmask applied to the interface.

scopeid: number | null

The IPv6 scope id or null.

cidr: string

The CIDR range.

mac: string

The MAC address.


interface Deno.QuicAcceptOptions

extends QuicServerTransportOptions
unstable

Type Parameters

ZRTT extends boolean

Properties

alpnProtocols: string[]
optional

Application-Layer Protocol Negotiation (ALPN) protocols to announce to the client. QUIC requires the use of ALPN.

zeroRtt: ZRTT = false
optional

Convert this connection into 0.5-RTT at the cost of weakened security, as 0.5-RTT data may be sent before TLS client authentication has occurred.


interface Deno.QuicBidirectionalStream

unstable

Properties

readable: QuicReceiveStream
readonly

Returns a QuicReceiveStream instance that can be used to read incoming data.

writable: QuicSendStream
readonly

Returns a QuicSendStream instance that can be used to write outgoing data.


interface Deno.QuicCloseInfo

unstable

Properties

closeCode: number

A number representing the error code for the error.

reason: string

A string representing the reason for closing the connection.


interface Deno.QuicConn

unstable

Properties

endpoint: QuicEndpoint
readonly

The endpoint for this connection.

handshake: Promise<void>
readonly

Returns a promise that resolves when the TLS handshake is complete.

remoteAddr: NetAddr
readonly

Return the remote address for the connection. Clients may change addresses at will, for example when switching to a cellular internet connection.

protocol: string | undefined
readonly

The negotiated ALPN protocol, if provided. Only available after the handshake is complete.

serverName: string | undefined
readonly

The negotiated server name. Only available on the server after the handshake is complete.

closed: Promise<QuicCloseInfo>
readonly

Returns a promise that resolves when the connection is closed.

incomingBidirectionalStreams: ReadableStream<QuicBidirectionalStream>
readonly

A stream of bidirectional streams opened by the peer.

incomingUnidirectionalStreams: ReadableStream<QuicReceiveStream>
readonly

A stream of unidirectional streams opened by the peer.

maxDatagramSize: number
readonly

Returns the datagram stream for sending and receiving datagrams.

Methods

close(info?: QuicCloseInfo): void

Close closes the listener. Any pending accept promises will be rejected with errors.

createBidirectionalStream(options?: QuicSendStreamOptions): Promise<QuicBidirectionalStream>

Opens and returns a bidirectional stream.

createUnidirectionalStream(options?: QuicSendStreamOptions): Promise<QuicSendStream>

Opens and returns a unidirectional stream.

sendDatagram(data: Uint8Array): Promise<void>

Send a datagram. The provided data cannot be larger than maxDatagramSize.

readDatagram(): Promise<Uint8Array<ArrayBuffer>>

Receive a datagram.


interface Deno.QuicEndpointOptions

unstable

Properties

hostname: string = "::"
optional

A literal IP address or host name that can be resolved to an IP address.

port: number = 0
optional

The port to bind to.


interface Deno.QuicIncoming

unstable

An incoming connection for which the server has not yet begun its part of the handshake.

Properties

localIp: string
readonly

The local IP address which was used when the peer established the connection.

remoteAddr: NetAddr
readonly

The peer’s UDP address.

remoteAddressValidated: boolean
readonly

Whether the socket address that is initiating this connection has proven that they can receive traffic.

Methods

accept<ZRTT extends boolean>(options?: QuicAcceptOptions<ZRTT>): ZRTT extends true ? QuicConn : Promise<QuicConn>

Accept this incoming connection.

refuse(): void

Refuse this incoming connection.

ignore(): void

Ignore this incoming connection attempt, not sending any packet in response.


interface Deno.QuicListener

extends AsyncIterable<QuicIncoming>
unstable

Specialized listener that accepts QUIC connections.

Properties

endpoint: QuicEndpoint
readonly

The endpoint for this listener.

Methods

incoming(): Promise<QuicIncoming>

Waits for and resolves to the next incoming connection.

accept(): Promise<QuicConn>

Wait for the next incoming connection and accepts it.

stop(): void

Stops the listener. This does not close the endpoint.

[[Symbol.asyncIterator]](): AsyncIterableIterator<QuicIncoming>

Iterates over the incoming connections received by the listener.


interface Deno.QuicListenOptions

extends QuicServerTransportOptions
unstable

Properties

alpnProtocols: string[]

Application-Layer Protocol Negotiation (ALPN) protocols to announce to the client. QUIC requires the use of ALPN.

key: string

Server private key in PEM format

cert: string

Cert chain in PEM format


interface Deno.QuicReceiveStream

extends ReadableStream<Uint8Array<ArrayBuffer>>
unstable

Properties

id: bigint
readonly

62-bit stream ID, unique within this connection.


interface Deno.QuicSendStream

extends WritableStream<Uint8Array<ArrayBufferLike>>
unstable

Properties

sendOrder: number

Indicates the send priority of this stream relative to other streams for which the value has been set.

id: bigint
readonly

62-bit stream ID, unique within this connection.


interface Deno.QuicSendStreamOptions

unstable

Properties

sendOrder: number = 0
optional

Indicates the send priority of this stream relative to other streams for which the value has been set.

waitUntilAvailable: boolean = false
optional

Wait until there is sufficient flow credit to create the stream.


interface Deno.QuicServerTransportOptions

extends QuicTransportOptions
unstable

Properties

preferredAddressV4: string = undefined
optional

Preferred IPv4 address to be communicated to the client during handshaking. If the client is able to reach this address it will switch to it.

preferredAddressV6: string = undefined
optional

Preferred IPv6 address to be communicated to the client during handshaking. If the client is able to reach this address it will switch to it.


interface Deno.QuicTransportOptions

unstable

Properties

keepAliveInterval: number = undefined
optional

Period of inactivity before sending a keep-alive packet. Keep-alive packets prevent an inactive but otherwise healthy connection from timing out. Only one side of any given connection needs keep-alive enabled for the connection to be preserved.

maxIdleTimeout: number = undefined
optional

Maximum duration of inactivity to accept before timing out the connection. The true idle timeout is the minimum of this and the peer’s own max idle timeout.

maxConcurrentBidirectionalStreams: number = 100
optional

Maximum number of incoming bidirectional streams that may be open concurrently.

maxConcurrentUnidirectionalStreams: number = 100
optional

Maximum number of incoming unidirectional streams that may be open concurrently.

congestionControl:
"throughput"
| "low-latency"
| "default"
= "default"
optional

The congestion control algorithm used when sending data over this connection.


interface Deno.ResolveDnsOptions

Options which can be set when using Deno.resolveDns.

Properties

nameServer: { ipAddr: string; port?: number; }
optional

The name server to be used for lookups.

If not specified, defaults to the system configuration. For example /etc/resolv.conf on Unix-like systems.

signal: AbortSignal
optional

An abort signal to allow cancellation of the DNS resolution operation. If the signal becomes aborted the resolveDns operation will be stopped and the promise returned will be rejected with an AbortError.


interface Deno.SoaRecord

If Deno.resolveDns is called with "SOA" record type specified, it will return an array of objects with this interface.

Properties

mname: string
rname: string
serial: number
refresh: number
retry: number
expire: number
minimum: number

interface Deno.SrvRecord

If Deno.resolveDns is called with "SRV" record type specified, it will return an array of objects with this interface.

Properties

priority: number
weight: number
port: number
target: string

interface Deno.StartTlsOptions

Options which can be set when upgrading an existing connection to TLS via Deno.startTls.

Properties

hostname: string = "127.0.0.1"
optional

A literal IP address or host name that can be resolved to an IP address.

caCerts: string[]
optional

A list of root certificates that will be used in addition to the default root certificates to verify the peer's certificate.

Must be in PEM format.

alpnProtocols: string[]
optional

Application-Layer Protocol Negotiation (ALPN) protocols to announce to the client. If not specified, no ALPN extension will be included in the TLS handshake.

unsafelyDisableHostnameVerification: boolean = false
optional

If true, the certificate's common name or subject alternative names will not be checked against the hostname provided in the options.

This disables hostname verification but still validates the certificate chain. Use with caution and only when connecting to known servers.


interface Deno.TcpConn

extends Conn<NetAddr>

A TCP stream connection.

Methods

setNoDelay(noDelay?: boolean): void

Sets the TCP_NODELAY option on this connection, which controls whether Nagle's algorithm is used.

Note that the boolean is noDelay, not "enable Nagle", so the sense is the opposite of enabling the algorithm:

  • setNoDelay(true) (the default) sets TCP_NODELAY, which disables Nagle's algorithm. Small writes are sent immediately with lower latency, at the cost of potentially more, smaller packets.
  • setNoDelay(false) clears TCP_NODELAY, which enables Nagle's algorithm. Small writes may be buffered and coalesced to reduce the number of packets sent.
setKeepAlive(keepAlive?: boolean): void

Enable or disable TCP keep-alive probes on this connection. Pass true to enable keep-alive and false to disable it.


interface Deno.TcpListenOptions

extends ListenOptions
unstable

Properties

reusePort: boolean = false
optional

When true the SO_REUSEPORT flag will be set on the listener. This allows multiple processes to listen on the same address and port.

On Linux this will cause the kernel to distribute incoming connections across the different processes that are listening on the same address and port.

This flag is only supported on Linux. It is silently ignored on other platforms.

Options which can be set when opening a TCP listener via Deno.listen.


interface Deno.TlsCertifiedKeyPem

Provides certified key material from strings. The key material is provided in PEM-format (Privacy Enhanced Mail, https://www.rfc-editor.org/rfc/rfc1422) which can be identified by having -----BEGIN----- and -----END----- markers at the beginning and end of the strings. This type of key is not compatible with DER-format keys which are binary.

Deno supports RSA, EC, and PKCS8-format keys.

const key = {
 key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
 cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n" }
};

Properties

keyFormat: "pem"
optional

The format of this key material, which must be PEM.

key: string

Private key in PEM format. RSA, EC, and PKCS8-format keys are supported.

cert: string

Certificate chain in PEM format.


interface Deno.TlsConn

extends Conn<NetAddr>

A TLS-encrypted stream connection over an IP-based transport.

Methods

handshake(): Promise<TlsHandshakeInfo>

Runs the client or server handshake protocol to completion if that has not happened yet. Calling this method is optional; the TLS handshake will be completed automatically as soon as data is sent or received.


interface Deno.TlsHandshakeInfo

Information about a completed TLS handshake.

Properties

alpnProtocol: string | null

Contains the ALPN protocol selected during negotiation with the server. If no ALPN protocol selected, returns null.


interface Deno.UdpListenOptions

extends ListenOptions
unstable

Unstable options which can be set when opening a datagram listener via Deno.listenDatagram.

Properties

reuseAddress: boolean = false
optional

When true the specified address will be reused, even if another process has already bound a socket on it. This effectively steals the socket from the listener.

loopback: boolean = false
optional

When true, sent multicast packets will be looped back to the local socket.


interface Deno.UnixAddr

The address of a network connection or listener using a Unix domain socket.

Properties

transport: "unix" | "unixpacket"

The Unix domain socket transport protocol.

path: string

The file system path to the socket.


interface Deno.UnixConn

extends Conn<UnixAddr>

A Unix domain socket stream connection.


interface Deno.UnixConnectOptions

Options which can be set when connecting to a Unix domain socket via Deno.connect.

Properties

transport: "unix"

The Unix domain socket transport protocol.

path: string

The file system path to the socket to connect to.


interface Deno.UnixListenDatagramOptions

unstable

Unstable options which can be set when opening a unixpacket datagram listener via Deno.listenDatagram.

Properties

path: string
optional

A path to the Unix Socket. When omitted the socket is left unbound, so it can be used to send messages but cannot receive them.


interface Deno.UnixListenOptions

Options which can be set when opening a Unix listener via Deno.listen or Deno.listenDatagram.

Properties

path: string

A path to the Unix Socket.


interface Deno.VsockAddr

unstable

The address of a network connection or listener using the VSOCK transport for communication between a virtual machine and its host.

Properties

transport: "vsock"

The VSOCK transport protocol.

cid: number

The context identifier (CID) of the peer.

port: number

The port number.


interface Deno.VsockConn

extends Conn<VsockAddr>

A VSOCK stream connection.


interface Deno.VsockConnectOptions

unstable

Options which can be set when connecting over VSOCK via Deno.connect.

Properties

transport: "vsock"

The VSOCK transport protocol.

cid: number

The context identifier (CID) of the peer to connect to.

port: number

The port to connect to.


interface Deno.VsockListenOptions

unstable

Options which can be set when opening a VSOCK listener via Deno.listen.

Properties

cid: number

The context identifier (CID) to listen on. Use -1 to listen on any CID.

port: number

The port to listen on.


type alias Deno.Addr

The address of a network connection or listener, regardless of transport.

Definition

NetAddr
| UnixAddr
| VsockAddr

type alias Deno.RecordType

The type of the resource record to resolve via DNS using Deno.resolveDns.

Only the listed types are supported currently.

Definition

"A"
| "AAAA"
| "ANAME"
| "CAA"
| "CNAME"
| "MX"
| "NAPTR"
| "NS"
| "PTR"
| "SOA"
| "SRV"
| "TXT"

type alias Deno.TcpListener

Specialized listener that accepts TCP connections.

Definition

Listener<TcpConn, NetAddr>

type alias Deno.TlsListener

Specialized listener that accepts TLS connections.

Definition

Listener<TlsConn, NetAddr>

type alias Deno.UnixListener

Specialized listener that accepts Unix connections.

Definition

Listener<UnixConn, UnixAddr>

type alias Deno.VsockListener

unstable

Specialized listener that accepts VSOCK connections.

Definition

Listener<VsockConn, VsockAddr>

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/deno/network

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API