Browser-compatible URL class, implemented by following the WHATWG URL Standard. Examples of parsed URLs may be found in the Standard itself.
Constructor
Variables
hostname:String
Gets and sets the hostname portion of the URL
The key difference between url.host and url.hostname is that url.hostname does not include the port.
port:String
Gets and sets the port portion of the URL.
The port value may be a number or a string containing a number in the range 0 to 65535 (inclusive).
Setting the value to the default port of the URL objects given protocol will result in the port value becoming the empty string ('').
read onlysearchParams:URLSearchParams
Gets the URLSearchParams object representing the query parameters of the URL.
This property is read-only; to replace the entirety of query parameters of the URL, use the url.search setter.
See URLSearchParams documentation for details.
Methods
toString():String
The toString() method on the URL object returns the serialized URL.
The value returned is equivalent to that of url.href and url.toJSON().
Because of the need for standard compliance, this method does not allow users to customize the serialization process of the URL.
For more flexibility, require('url').format() method might be of interest.