Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/net/mod.ts>getAvailablePort

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function getAvailablePort
import { getAvailablePort } from "https://deno.land/std@0.220.1/net/mod.ts";

Returns an available network port.

Examples

Example 1

import { getAvailablePort } from "https://deno.land/std@0.220.1/net/get_available_port.ts";

const port = getAvailablePort();
Deno.serve({ port }, () => new Response("Hello, world!"));

Returns

number