<p dir="auto">To extract the port from a random port in a Deno.listen is somewhat painful:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    const listener = Deno.listen({ port: 0, transport: &quot;tcp&quot; });
    //@ts-ignore
    const {port} = listener.addr
    this.port = port"><pre class="notranslate"><code class="notranslate">    const listener = Deno.listen({ port: 0, transport: "tcp" });
    //@ts-ignore
    const {port} = listener.addr
    this.port = port
</code></pre></div>
<p dir="auto">While the random port doesn't seem that useful, it is extremely. For unit tests,  launching a listener or process at a random port means that unit tests can really be independent, and not hardcoded.</p>
<p dir="auto">Ctrl+Z stopped Deno run<br>
but I don't know why, after another <code class="notranslate">deno run</code> the port of the server (was 8080) were still in use.<br>
so I tried to use a random free port with the 0.</p>
<p dir="auto">after a console.warn(server), I got:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Server {
 listener: ListenerImpl { rid: 5, addr: { hostname: &quot;127.0.0.1&quot;, port: 34263, transport: &quot;tcp&quot; } },
 closing: false,
 connections: []
}"><pre class="notranslate"><code class="notranslate">Server {
 listener: ListenerImpl { rid: 5, addr: { hostname: "127.0.0.1", port: 34263, transport: "tcp" } },
 closing: false,
 connections: []
}
</code></pre></div>
<p dir="auto">but when I tried to access to the port with <code class="notranslate">server.listener.addr.port</code>, I had this message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error TS2339: Property 'port' does not exist on type 'Addr'.
  Property 'port' does not exist on type 'UnixAddr'."><pre class="notranslate"><code class="notranslate">error TS2339: Property 'port' does not exist on type 'Addr'.
  Property 'port' does not exist on type 'UnixAddr'.
</code></pre></div>
<p dir="auto">it doesn't make sense. it seems like port is not defined on type Addr (obvious but confusing)</p>