url.hostname
This function returns the hostname for the URL, removing any valid port number if present. If the input is enclosed in square brackets, as literal IPv6 addresses are, the square brackets are removed from the output.
Syntax
url.hostname(rawURLString)
Arguments
Argument |
Type |
Description |
---|---|---|
rawURLString |
string |
Raw URL string |
Returns
Type |
Description |
---|---|
string |
The hostname of the rawURLString |
Examples
The function url.hostname("https://example.com:8080/root-path/sub-path?query=example+query+%2F+question#fragment")
returns example.com
.