Skip to content
Related Articles
Open in App
Not now

Related Articles

Node.js URL Complete Reference

Improve Article
Save Article
  • Last Updated : 28 Feb, 2023
Improve Article
Save Article

The ‘url’ module provides utilities for URL resolution and parsing. The getters and setters implement the properties of URL objects on the class prototype, and the URL class is available on the global object.



// Create a test URLSearchParams object
var searchpar = new URLSearchParams("keya=vala&keyb=valb");
// Display the key/value pairs
for(var pair of searchpar.entries()) {
console.log(pair[0]+ ', '+ pair[1]);


keya, vala
keyb, valb

The Complete list of URL is listed below:



 URL()It is  provides utilities for URL resolution and parsing
url.toString()It is an inbuilt application programming interface(API) of the URL module
URL.toJSON()Return the serialized URL of the URL object. 
url.domainToUnicode()Get the domain for the particular ASCII value.



hash Get and set the fragment portion of the URL.
host APIGet and set the host portion of the URL.
origin APIThis url.origin is an inbuilt application programming interface(API) of the URL class
username APIGet and set the username of URL. 
search APIGet and set the query part of URL. 
port APIGet and set the port portion of the URL.the port value may be a number
pathname APIGet and set the pathname portion of the URL.
password APIGet and set the password portion of the URL. 
href APIIt is an Inbuilt application programming interface of class URL with in the url module
hostname APIGet and set the hostname portion of the URL.
pathToFileURL APIConverts the path to a file and ensures that the URL control characters (/, \, : ) 
fileURLToPath APIDecodes the file URL to a path string and ensures that the URL control characters (/, %)
parse(urlString, parseQueryString, slashesDenoteHost) It is takes a URL string, parses it, and it will return a URL object with each part of the address as properties.
Special Schemes of protocol APIGet and set the protocol scheme of the URL.
protocolGet and set the protocol portion of the URL.
domainToASCIIIt is an inbuilt application programming interface of class URL with in url module.
domainToUnicodeIt is an inbuilt application programming interface of class URL with in url module.
resolve(from,to)It is an nbuilt method of class URL that resolves a target URL relative to a base URL.
format(urlObject)It is an nbuilt API provided by URL class, which takes an object or string 
formatWith the help of url.format()method, we are able to format the hostname according to our need.

Class: URLSearchParams

Class: URLSearchParams


append()This method adds a key/value pair specified by user.
delete()This  method deletes the parameter specified by user and all its associated values.
entries()Returns an iterator which allows to iterate through all the key/value pairs present in the object.
forEach()Returns an iterator which allows to iterate through all values contained in this object with the help of a callback function.
get()Returns the first value of the input search parameter.
get()Get the value for particular name entry present in the URL search params object.
getAll()Returns all the values of the input search parameter in the form of an array.
sort()This method uses stable sorting algorithm.
toString()Get the object of uri search params object as a string.
keys()Get the iterator object containing all the name entries only of URL search params object.
values()In URLSearchParams interface, the values() method returns an iterator 
set()Sets the value given as an input parameter.
toString()Returns a query string which is suitable for use in a URL.
keys()In URLSearchParams interface, the keys() method returns an Iterator 
has()In URLSearchParams interface, the has() method returns a Boolean 

Legacy urlObject

authReturn the string of parameters.
hashIt is used for identifying the “fragment” portion of a URL.
hostReturn the host name in the url as a string.
searchGet the search query within the hostname which is followed by the ‘?’ character.
protocolIt is used by the given hostname.
hrefReturn the complete URL string along with the protocols(HTTP) and pathname or other search terms.
queryCheck whether the query is a string or an object.
slashesIt is used when one wants to check whether there is a need of ASCII valued forward-slash character (/) after the colon (:) 
portGet the numeric port portion of the host component within the hostname.
pathname It is used by the given hostname.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!