Open In App

Node.js urlObject.hash API

Last Updated : 14 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Before we go on to learn about URL objects API we need to know a brief about URL.

If you ever wanted to provide utilities so as to parse or resolute your URL, we can do it through the URL Module.

We can divide the URL Module into two parts:- These are- URL String and URL Object. The urlObjectHash is a part of URL Object which is generally based on Legacy API (Though a newer API is also provided by the name of WHATWG URL Standard)

urlObject.hash: It is used for identifying the “fragment” portion of a URL. This property also includes the # character.

For example: '#hash'.

Syntax

urlObject.hash

Example:




const url = require('url');
const reqUrl = 'www.example.com/hi#file?=newFile'
const urlObject = url.parse(reqUrl, true);
  
console.log(urlObject.hash);


OUTPUT:

#file?=newFile

Previous Article
Next Article

Similar Reads

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 urlObject.auth API
With the help of urlObject.auth() method, we can find the authentication parameter within the hostname. This method returns the string of parameters. Syntax : urlObject.auth() Return: Returns the string of authentication parameters. Example 1: In this example with the help of urlObject.auth() method we are able to extract the username and password
1 min read
Node.js urlObject.protocol API
With the help of urlObject.protocol() method, we can find the name of protocol which is used by the given hostname. Syntax : urlObject.protocol() Return : Returns the protocol used (i.e. - http, https, ftp, etc.) Example #1 : In this example, with the help of urlObject.protocol() method we are able to extract the protocol used from the hostname. //
1 min read
Node.js urlObject.search API
The urlObject.search() method in Node is used to get the search query within the hostname which is followed by the '?' character. Syntax : urlObject.search() Return : Returns the search query after '?' character. Example #1 : In these examples, we have shown how the urlObject.search() method is able to extract the search query from the hostname. //
1 min read
Node.js urlObject.host API
The utilities for URL resolution and parsing is provided by the URL module. A URL string is a structured string that contains various multiple meaningful components. When parsed, a URL object is returned that contains properties for each of these components. url.host() return the host name in the url as a string. Examples: http://localhost:8080/reg
1 min read
Node.js urlObject.port API
The urlObject.port() method in Node is used to get the numeric port portion of the host component within the hostname. The URL’s port number is returned otherwise None if the port number is not present in the URL. Syntax: urlObject.port() Return: Returns the URL port number or None Example 1: In these examples, we have shown how the urlObject.port(
1 min read
Node.js urlObject.pathname API
With the help of urlObject.pathname() method, we can find the name of the path which is used by the given hostname. This contains all the things starting from the host (with the port) and before the beginning of the query or hash components, which are delimited by one of the ASCII question mark (?) or hash (#) characters. Syntax: urlObject.pathname
1 min read
Node.js urlObject.hostname API
The url.hostname is an inbuilt application programming interface of class URL within the url module which is used to get and set the hostname portion of the URL. The url.hostname does not include the port number. Syntax: url.hostname It associates by single value url which is an object created by URL constructor. Example: // Node program to demonst
1 min read
Node.js urlObject.query API
The urlObject.query is the query string returned without the ASCII question mark (?) or an object returned by the query string module named as parse() method. The url.parse() method is used to check whether the query is a string or an object. Basically, the argument (parseQueryString) that is passed to url.parse() method to tell the nature of the q
2 min read
Node.js urlObject.href API
The urlObject.href API is used to return the complete URL string along with the protocols(HTTP) and pathname or other search terms. Syntax: urlObject.hrefFor example: 'http://www.geeksforgeeks.com/login/password.html' Here, Protocol = http Path = /login Host = 'www' File Name = password.html Example 1: The below example illustrates the use of urlOb
1 min read