Node.js URL Complete Reference
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.
Example:
Javascript
// 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]); } |
Output:
keya, vala keyb, valb
The Complete list of URL is listed below:
Methods | Description |
---|---|
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. |
API | Description |
---|---|
hash | Get and set the fragment portion of the URL. |
host API | Get and set the host portion of the URL. |
origin API | This url.origin is an inbuilt application programming interface(API) of the URL class |
username API | Get and set the username of URL. |
search API | Get and set the query part of URL. |
port API | Get and set the port portion of the URL.the port value may be a number |
pathname API | Get and set the pathname portion of the URL. |
password API | Get and set the password portion of the URL. |
href API | It is an Inbuilt application programming interface of class URL with in the url module |
hostname API | Get and set the hostname portion of the URL. |
pathToFileURL API | Converts the path to a file and ensures that the URL control characters (/, \, : ) |
fileURLToPath API | Decodes 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 API | Get and set the protocol scheme of the URL. |
protocol | Get and set the protocol portion of the URL. |
domainToASCII | It is an inbuilt application programming interface of class URL with in url module. |
domainToUnicode | It 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 |
format | With the help of url.format()method, we are able to format the hostname according to our need. |
Class: URLSearchParams
Class: URLSearchParams | Description |
---|---|
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
auth | Return the string of parameters. |
hash | It is used for identifying the “fragment” portion of a URL. |
host | Return the host name in the url as a string. |
search | Get the search query within the hostname which is followed by the ‘?’ character. |
protocol | It is used by the given hostname. |
href | Return the complete URL string along with the protocols(HTTP) and pathname or other search terms. |
query | Check whether the query is a string or an object. |
slashes | It is used when one wants to check whether there is a need of ASCII valued forward-slash character (/) after the colon (:) |
port | Get the numeric port portion of the host component within the hostname. |
pathname | It is used by the given hostname. |
Please Login to comment...