Skip to main content
Network - Deno documentation

Functions

f
Deno.connect
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`). ```ts 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".
f
Deno.connectTls
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. ```ts 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.
f
Deno.listen
Listen announces on the local transport address. ```ts 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.
f
Deno.listenDatagram
Listen announces on the local transport address. ```ts const listener1 = Deno.listenDatagram({ port: 80, transport: "udp" }); const listener2 = Deno.listenDatagram({ hostname: "golang.org", port: 80, transport: "udp" }); ``` Requires `allow-net` permission.
f
Deno.listenTls
Listen announces on the local transport address over TLS (transport layer security). ```ts using listener = Deno.listenTls({ port: 443, cert: Deno.readTextFileSync("./server.crt"), key: Deno.readTextFileSync("./server.key"), }); ``` Requires `allow-net` permission.
f
Deno.networkInterfaces
Returns an array of the network interface information. ```ts console.log(Deno.networkInterfaces()); ``` Requires `allow-sys` permission.
f
Deno.resolveDns
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. ```ts const a = await Deno.resolveDns("example.com", "A"); const aaaa = await Deno.resolveDns("example.com", "AAAA", { nameServer: { ipAddr: "8.8.8.8", port: 53 }, }); ``` Requires `allow-net` permission.
f
Deno.startTls
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. ```ts 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.

Interfaces

I
Deno.CaaRecord
If [`Deno.resolveDns`](./././~/Deno.resolveDns) is called with `"CAA"` record type specified, it will resolve with an array of objects with this interface.
I
Deno.ConnectOptions
No documentation available
I
Deno.DatagramConn
A generic transport listener for message-oriented protocols.
I
Deno.Listener
A generic network listener for stream-oriented protocols.
I
Deno.ListenOptions
No documentation available
I
I
Deno.MulticastV4Membership
Represents membership of a IPv4 multicast group.
I
Deno.MulticastV6Membership
Represents membership of a IPv6 multicast group.
I
Deno.MxRecord
If [`Deno.resolveDns`](./././~/Deno.resolveDns) is called with `"MX"` record type specified, it will return an array of objects with this interface.
I
Deno.NaptrRecord
If [`Deno.resolveDns`](./././~/Deno.resolveDns) is called with `"NAPTR"` record type specified, it will return an array of objects with this interface.
I
Deno.NetAddr
No documentation available
I
Deno.NetworkInterfaceInfo
The information for a network interface returned from a call to [`Deno.networkInterfaces`](./././~/Deno.networkInterfaces).
I
Deno.ResolveDnsOptions
Options which can be set when using [`Deno.resolveDns`](./././~/Deno.resolveDns).
I
Deno.SoaRecord
If [`Deno.resolveDns`](./././~/Deno.resolveDns) is called with `"SOA"` record type specified, it will return an array of objects with this interface.
I
Deno.SrvRecord
If [`Deno.resolveDns`](./././~/Deno.resolveDns) is called with `"SRV"` record type specified, it will return an array of objects with this interface.
I
Deno.TcpConn
No documentation available
I
Deno.TcpListenOptions
No documentation available
I
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. ```ts const key = { key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n", cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n" } }; ```
I
Deno.TlsConn
No documentation available
I
Deno.TlsHandshakeInfo
No documentation available
I
Deno.UdpListenOptions
Unstable options which can be set when opening a datagram listener via [`Deno.listenDatagram`](./././~/Deno.listenDatagram).
I
Deno.UnixAddr
No documentation available
I
Deno.UnixConn
No documentation available
I
Deno.UnixConnectOptions
No documentation available
I
Deno.UnixListenOptions
Options which can be set when opening a Unix listener via [`Deno.listen`](./././~/Deno.listen) or [`Deno.listenDatagram`](./././~/Deno.listenDatagram).

Type Aliases

T
Deno.Addr
No documentation available
T
Deno.RecordType
The type of the resource record to resolve via DNS using [`Deno.resolveDns`](./././~/Deno.resolveDns). Only the listed types are supported currently.
T
Deno.TcpListener
Specialized listener that accepts TCP connections.
T
Deno.TlsListener
Specialized listener that accepts TLS connections.
T
Deno.UnixListener
Specialized listener that accepts Unix connections.