Last active
March 30, 2024 04:14
-
-
Save aboqasem/a3f016f461ab405255584d2d6592a635 to your computer and use it in GitHub Desktop.
Get a random available port in Bun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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