Skip to main content

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

Classes

c
Deno.QuicEndpoint
No documentation available

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).

    f
    Deno.connectQuic

    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.

      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.

        f
        Deno.listen

        Listen announces on the local transport address.

          f
          Deno.listenDatagram

          Listen announces on the local transport address.

            f
            Deno.listenTls

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

              f
              Deno.networkInterfaces

              Returns an array of the network interface information.

                f
                Deno.resolveDns

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

                  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.

                    f
                    Deno.upgradeWebTransport

                    Upgrade a QUIC connection into a WebTransport instance.

                      Interfaces

                      I
                      Deno.CaaRecord

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

                      I
                      Deno.Conn

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

                      I
                      Deno.ConnectOptions

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

                      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

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

                      I
                      Deno.ListenTlsOptions

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

                      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 is called with "MX" record type specified, it will return an array of objects with this interface.

                      I
                      Deno.NaptrRecord

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

                      I
                      Deno.NetAddr

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

                      I
                      Deno.NetworkInterfaceInfo

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

                      I
                      Deno.QuicCloseInfo
                      No documentation available
                      I
                      Deno.QuicEndpointOptions
                      No documentation available
                      I
                      Deno.QuicIncoming

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

                      I
                      Deno.QuicListener

                      Specialized listener that accepts QUIC connections.

                      I
                      Deno.QuicReceiveStream
                      No documentation available
                      I
                      Deno.QuicSendStream
                      No documentation available
                      I
                      Deno.ResolveDnsOptions

                      Options which can be set when using Deno.resolveDns.

                      I
                      Deno.SoaRecord

                      If 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 is called with "SRV" record type specified, it will return an array of objects with this interface.

                      I
                      Deno.StartTlsOptions

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

                      I
                      Deno.TcpConn

                      A TCP stream connection.

                      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.

                      I
                      Deno.TlsConn

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

                      I
                      Deno.TlsHandshakeInfo

                      Information about a completed TLS handshake.

                      I
                      Deno.UdpListenOptions

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

                      I
                      Deno.UnixAddr

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

                      I
                      Deno.UnixConn

                      A Unix domain socket stream connection.

                        I
                        Deno.UnixConnectOptions

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

                        I
                        Deno.UnixListenDatagramOptions

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

                        I
                        Deno.UnixListenOptions

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

                        I
                        Deno.VsockAddr

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

                        I
                        Deno.VsockConn

                        A VSOCK stream connection.

                          I
                          Deno.VsockConnectOptions

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

                          I
                          Deno.VsockListenOptions

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

                          Type Aliases

                          T
                          Deno.Addr

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

                            T
                            Deno.RecordType

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

                              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.

                                    T
                                    Deno.VsockListener

                                    Specialized listener that accepts VSOCK connections.


                                      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 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 for "unix".

                                      Parameters #

                                      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 #

                                      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 #

                                      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 #

                                      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 #

                                      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 and allow-write permission.

                                      Parameters #

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

                                      Return Type #

                                      Overload 3

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

                                      Listen announces on the local transport address.

                                      Parameters #

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

                                      Return Type #


                                      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 #

                                      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 and allow-write permission.

                                      Parameters #

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

                                      Return Type #




                                      function Deno.resolveDns

                                      allow-net

                                      Overload 1

                                      #resolveDns(
                                      query: string,
                                      recordType:
                                      "A"
                                      | "AAAA"
                                      | "ANAME"
                                      | "CNAME"
                                      | "NS"
                                      | "PTR"
                                      ,
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<string[]>

                                      Overload 2

                                      #resolveDns(
                                      query: string,
                                      recordType: "CAA",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<CaaRecord[]>

                                      Overload 3

                                      #resolveDns(
                                      query: string,
                                      recordType: "MX",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<MxRecord[]>

                                      Overload 4

                                      #resolveDns(
                                      query: string,
                                      recordType: "NAPTR",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<NaptrRecord[]>

                                      Overload 5

                                      #resolveDns(
                                      query: string,
                                      recordType: "SOA",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<SoaRecord[]>

                                      Overload 6

                                      #resolveDns(
                                      query: string,
                                      recordType: "SRV",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<SrvRecord[]>

                                      Overload 7

                                      #resolveDns(
                                      query: string,
                                      recordType: "TXT",
                                      ): 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.
                                      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.

                                      Parameters #

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

                                      Return Type #

                                      Promise<string[][]>

                                      Overload 8

                                      #resolveDns(
                                      query: string,
                                      recordType: RecordType,
                                      ): 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.
                                      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.

                                      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.


                                      interface Deno.ConnectQuicOptions

                                      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.

                                      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.


                                      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

                                      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.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.QuicAcceptOptions

                                      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.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 #

                                      The endpoint for this connection.

                                      #handshake: Promise<void>
                                      readonly

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

                                      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.

                                      A stream of bidirectional streams opened by the peer.

                                      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.

                                      Opens and returns a bidirectional stream.

                                      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.

                                      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 #

                                      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.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

                                      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.

                                      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.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

                                      Enable/disable the use of Nagle's algorithm.

                                      #setKeepAlive(keepAlive?: boolean): void

                                      Enable/disable keep-alive functionality.


                                      interface Deno.TcpListenOptions

                                      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 #

                                      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

                                      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.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.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.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.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"





                                      Did you find what you needed?

                                      Privacy policy