Home > vm-providers > getFreePort
Returns a free TCP port on the local IP address specified by the host parameter.
Signature:
export declare function getFreePort({ host }: {
host: string;
}): Promise<number>;
Parameter | Type | Description |
---|---|---|
{ host } | { host: string; } |
Returns:
Promise<number>
An unused port number chosen by the operating system.
This function internally creates a TCP server with port 0 so that, as mentioned in the node.js documentation, the operating system can assign an arbitrary unused port. The function then closes the server and returns the port number.