Assistive-Webdriver

Home > vm-providers > getFreePort

getFreePort() function

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>;

Parameters

Parameter Type Description
{ host } { host: string; }  

Returns:

Promise<number>

An unused port number chosen by the operating system.

Remarks

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.