Skip to content

Commit

Permalink
fix(getport): only run ".unref" if it exists
Browse files Browse the repository at this point in the history
fixes #801
  • Loading branch information
hasezoey committed Oct 5, 2023
1 parent 308cf01 commit 73c0c2e
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -102,7 +102,11 @@ export function validPort(port: number): number {
export function tryPort(port: number): Promise<boolean> {
return new Promise((res, rej) => {
const server = http.createServer();
server.unref(); // dont keep this server from exiting the application

// some engines dont support ".unref"(net / tcp.unref), like "deno" in the past and now "bun"
if (typeof server.unref === 'function') {
server.unref(); // dont keep this server from exiting the application
}

server.on('error', (err) => {
if ((err as any)?.code !== 'EADDRINUSE') {
Expand Down

0 comments on commit 73c0c2e

Please sign in to comment.