* A port only counts as free when BOTH the v4 wildcard (0.0.0.0) and the * loopback (127.0.0.1) bind succeed. One bind is not enough on macOS/BSD: * SO_REUSEADDR (node's default) lets a specific-address bind succeed while * a wildcard listener holds the port — and vice versa — so probing only *
(port: number)
| 33 | * 0.0.0.0 each miss one mode; the conjunction catches all four. |
| 34 | */ |
| 35 | async function isPortFree(port: number): Promise<boolean> { |
| 36 | return (await bindable(port, '0.0.0.0')) && (await bindable(port, '127.0.0.1')) |
| 37 | } |
| 38 | |
| 39 | function bindable(port: number, host: string): Promise<boolean> { |
| 40 | return new Promise((res) => { |
no test coverage detected