Skip to content

Instantly share code, notes, and snippets.

@aboqasem
Last active March 30, 2024 04:14
Show Gist options
  • Save aboqasem/a3f016f461ab405255584d2d6592a635 to your computer and use it in GitHub Desktop.
Save aboqasem/a3f016f461ab405255584d2d6592a635 to your computer and use it in GitHub Desktop.
Get a random available port in Bun
function randomAvailablePort(): number {
const server = Bun.serve({ fetch: () => new Response(), port: 0 });
const port = server.port;
server.stop(true);
return port;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment