The Wayback Machine - https://web.archive.org/web/20240911001613/https://www.geeksforgeeks.org/node-js-url-complete-reference/
Open In App

Node.js URL Complete Reference

Last Updated : 04 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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
const searchpar = new URLSearchParams("keya=vala&keyb;=valb");
 
// Display the key/value pairs
for (let 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 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 within 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 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 within url module.
domainToUnicode It is an inbuilt application programming interface of class URL within url module.
resolve(from,to) It is an inbuilt method of class URL that resolves a target URL relative to a base URL.
format(urlObject) It is an inbuilt 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 needs.

Class: URLSearchParams

Class: URLSearchParams

Description

append() This method adds a key/value pair specified by the user.
delete() This method deletes the parameter specified by the user and all its associated values.
entries() Returns an iterator that allows iterating through all the key/value pairs present in the object.
forEach() Returns an iterator that allows iterating 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 a 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 a stable sorting algorithm.
toString() Get the object of uri search params to the object as a string.
keys() Get the iterator object containing all the name entries only of the URL search params object.
values() In the URLSearchParams interface, the values() method returns an iterator 
set() Sets the value given as an input parameter.
toString() Returns a query string that is suitable for use in a URL.
keys() In the URLSearchParams interface, the keys() method returns an Iterator 
has() In the 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 hostname 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 for 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.


Previous Article
Next Article

Similar Reads

Convert relative path URL to absolute path URL using JavaScript
Given a relative URL, the task is to convert the relative URL to an absolute URL. Here, the base URL is also given. 2 approaches are discussed here, the first example has the baseURL provided by the user and the second takes it from the URL of the page. Approach 1: Get the relURL and baseURL from user.Use .split() method to split the base and relat
3 min read
What is URL Locator & what are common schemes used for the URL in HTML ?
Every HTML document on the internet has a unique URL. URL stands for Uniform Resource Locator. The URL is the HTML document's address on the internet. Any file that can be accessed via the internet has a URL, including images, JavaScript files, CSS files, Flash files, and so on. To view an HTML document in a browser, enter the URL of the document i
2 min read
Node.js String Decoder Complete Reference
The string Decoder module provides an API for decoding Buffer objects into strings. Example: C/C++ Code // Node.js program to demonstrate the // stringDecoder.write() Method // Import the string_decoder module // and get the StringDecoder class // using object destructuring const { StringDecoder } = require("string_decoder"); // Create a
1 min read
Node.js HTTP Module Complete Reference
To make HTTP requests in Node.js, there is a built-in module HTTP in Node.js to transfer data over the HTTP. To use the HTTP server in the node, we need to require the HTTP module. The HTTP module creates an HTTP server that listens to server ports and gives a response back to the client. Example: C/C++ Code // Node.js program to demonstrate the //
4 min read
Node.js Buffer Complete Reference
Buffers are instances of the Buffer class in Node.js. Buffers are designed to handle binary raw data. Buffers allocate raw memory outside the V8 heap. Buffer class is a global class so it can be used without importing the Buffer module in an application. Example: C/C++ Code <script> // Node.js program to demonstrate the // Buffer.allocUnsafeS
8 min read
Node.js Crypto Complete Reference
Node.js crypto module handles cryptographic functionality. Cryptography is an important aspect when we deal with network security. ‘Crypto’ means secret or hidden. Cryptography is the science of secret writing with the intention of keeping the data secret. Example: C/C++ Code <script> // Node.js program to demonstrate the // cipher.final() me
5 min read
Node.js Assert Complete Reference
Assert module in Node.js provides a bunch of facilities that are useful for the assertion of the function. The assert module provides a set of assertion functions for verifying invariants. If the condition is true it will output nothing else an assertion error is given by the console. Example: C/C++ Code // Requiring the module const assert = requi
2 min read
Node.js OS Complete Reference
Node.js OS module provides information about the computer operating system. Below example illustrate the os.version() method in Node.js: Example: C/C++ Code // Import the os module const os = require("os"); let osVersion = os.version(); console.log("OS Version:", osVersion); Output: OS Version: Windows 10 Enterprise The Complete
2 min read
Node.js DNS Complete Reference
Node.js DNS is a node module used to do name resolution facility which is provided by the operating system as well as used to do an actual DNS lookup. Example: C/C++ Code <script> // Node.js program to demonstrate the // dns.resolve() method // Accessing dns module const dns = require('dns'); // Set the rrtype for dns.resolve() method const r
3 min read
Node.js Globals Complete Reference
Node.js Global Objects are the objects that are available in all modules. Global Objects are built-in objects that are part of the JavaScript and can be used directly in the application without importing any particular module. Example: It repeats the execution of the callback after every t time in milliseconds passed as a parameter. C/C++ Code // E
2 min read
Node.js Path Module Complete Reference
The Path Module in Node.js provides the utilities for working with file and directory paths. Example: C/C++ Code // Import the path module const path = require('path'); // CASE 1 // If "dir", "root" and "base" are all given, // "root" is ignored. let path1 = path.format({ root: "C:\\ignored\\root",
2 min read
Node.js Stream Complete Reference
Node.js streams are a type of data-handling method and are used to read or write input into output sequentially. Streams are used to handle reading/writing files or exchanging information efficiently. Example: C/C++ Code // Node.js program to demonstrate the // writable.write() method // Including stream module const stream = require('stream'); //
3 min read
Node.js Query String Complete Reference
Node.js query String module is used as utilities for parsing and formatting URL query strings. It can be used to convert query string into JSON object and vice-versa. Example: C/C++ Code // Import the querystring module const querystring = require("querystring"); // Specify the URL query string // to be parsed let urlQuery = "usernam
1 min read
Node.js HTTP2 Complete Reference
HTTP2 module is used to provide an implementation of the HTTP2 protocol. It reduces overheads by compressing the server request headers. Example: C/C++ Code // Node.js program to demonstrate the // close event method const http2 = require('http2'); const fs = require('fs'); // Private key and public certificate for access const options = { key: fs.
6 min read
Node.js UDP/DataGram Complete Reference
Node.js UDP/DataGram module provides an implementation of UDP datagram sockets. Example: C/C++ Code // Importing dgram module const dgram = require('dgram'); // Creating and initializing client // and server socket const client = dgram.createSocket("udp4"); const server = dgram.createSocket("udp4"); // Catching the message event
2 min read
Node.js Utility Complete Reference
The Util module in node.js provides access to various utility functions. There are various utility modules available in the node.js module library. The modules are extremely useful in developing node based web applications. The Complete list of utility are listed below: Util Description Utility ModuleIt provides access to various utility functions.
4 min read
Node.js V8 Complete Reference
The v8 module exposes APIs that are specific to the version of V8 built into the Node.js binary. Example: C/C++ Code // Accessing v8 module const v8 = require('v8'); // Calling v8.getHeapStatistics() console.log(v8.getHeapStatistics()); Output: { total_heap_size: 6537216, total_heap_size_executable: 1048576, total_physical_size: 6537216, total_avai
2 min read
Node.js Timers Complete Reference
Node.js Timers module in Node.js contains various functions that allow us to execute a block of code or a function after a set period of time. The Timers module is global, we do not need to use require() to import it. Example: C/C++ Code // Node.js program to demonstrate the // Immediate Class methods // Setting Immediate by setImmediate Method con
2 min read
Node.js TLS/SSL Complete Reference
The tls module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that are built on top of OpenSSL. Example: C/C++ Code // Node.js program to demonstrate the // tls.getCiphers() method const tls = require('tls'), fs = require('fs'), // Port and host address for server PORT = 1337, HOST = '127.0.
3 min read
Node.js VM Complete Reference
The VM module enables compiling and running code within V8 Virtual Machine contexts. Example: C/C++ Code // Node.js program to demonstrate the // script.runInContext() method // Including util and vm module const util = require('util'); const vm = require('vm'); // Constructing context const contextobj = { name: 'Nidhi', articles: 60 }; // Construc
2 min read
Node.js Zlib Complete Reference
The zlib module provides compression functionality implemented using Gzip, Deflate/Inflate, and Brotli. The Complete Reference of Zlib are listed below: Methods Description zlib.constantsIt is used to yields an object listing Zlib-related constants. zlib.createBrotliCompress()It is used to create BrotliCompress object. zlib.createBrotliDecompress()
2 min read
Node.js Process Complete Reference
A process object is a global object that gives information about and controls the node.js process. As it is global, it can be used in the project without importing it from any module. Table of Content Understanding Node.js ProcessesEvents and Event-driven ArchitectureExecution Models and Asynchronous ProgrammingUnderstanding Node.js ProcessesSingle
5 min read
Node.js File System Complete Reference
Node.js File System module is used to handle file operations like creating, reading, deleting, etc. Node.js provides an inbuilt module called FS (File System). Node.js gives the functionality of file I/O by providing wrappers around the standard POSIX functions. All file system operations can have synchronous and asynchronous forms depending on use
15+ min read
Node.js Questions Complete Reference
Most people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs like Web App or Mobile App. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on. You need to remember that NodeJS is not a framework, and it’s not a programming la
13 min read
Node.js Console Complete Reference
The console module in Node.js provides a set of functions to output information to the terminal or command line, helping with debugging and logging. It is a built-in utility that is essential for monitoring and troubleshooting Node.js applications. It is a global object that provides a simple debugging console similar to JavaScript to display diffe
4 min read
How to get complete current page URL in PHP ?
In PHP. there is a superglobal variable that can provide you with the URL of the current working page. The $_SERVER is an inbuilt variable that can access the page URL, after that, you have to check that the URL is following which type of HTTP protocol. What is Superglobal? Superglobals are already defined variables by the PHP engine which can be u
1 min read
Node.js URL.domainToUnicode
The url.domainToUnicode is an inbuilt application programming interface of class URL with in url module. It returns the Unicode serialization of the domain. If the domain is invalid, the empty string is returned. Syntax : const url.domainToASCII Domain value : string Return value : string Example : const url = require('url'); console.log(url.domain
1 min read
Node.js URL.format(urlObject) API
The URL.format(urlObject) is the inbuilt API provided by URL class, which takes an object or string and return a formatted string derived from that object or string. Syntax: const url.format(urlObject) If the urlObject is not an object or string, then it will throw a TypeError. Return value: It returns string derived from urlObject. The urlObject c
4 min read
Node.js URL.hash API
The url.hash is an inbuilt application programming interface of class URL within url module which is used to get and set the fragment portion of the URL. Syntax: url.hash Return value: It gets and sets the fragment portion of the URL. Below programs illustrate the use of url.hash Method: Example 1: C/C++ Code // node program to demonstrate the // u
1 min read
Node.js URL.host API
The url.host is an inbuilt application programming interface of class URL with in url module which is used to get and set the host portion of the URL. Syntax: const url.host Return value: It gets and sets the host portion of the URL.Below programs illustrates the use of url.host Method:Example 1: C/C++ Code // node program to demonstrate the // url
1 min read