• Node.js Video Tutorials

NodeJS - urlObject.slashes Property



The NodeJS urlObject.slashes property of urlObject retrieves a Boolean value. The returned value will be true, if two ASCII forward slashes (//) are required after the colon (:) in the protocol segment of the URL. Else, the returned value is false.

The URL (Uniform Resource Locator) is a unique web address for a specific resource present in the various web servers.

The protocols present in the URL specify how data is transferred between the host and a web browser. The most common protocols you find the URLs are HTTP and HTTPS (secure), but there are other internet protocols such as FTP, UDP, POP, SMTP, DNS, etc.

Syntax

Following is the syntax of the NodeJS urlObject.slashes property

urlObject.slashes

Parameters

This property does not accept any parameters.

Return Value

This property returns a Boolean value. It will return true, if two ASCII forward-slash characters (//) are required after the colon in the protocol segment. Else, it returns false.

Example

In this example, we are checking whether there is a need for two ASCII forward-slash (//) after the colon (:) in the protocol of a URL.

const url = require('url');

console.log(url.parse('ARP://site.com').slashes);
console.log(url.parse('DHCP://site.com').slashes);
console.log(url.parse('IMAP4://site.com').slashes);
console.log(url.parse('SIP://site.com').slashes);
console.log(url.parse('RTP://site.com').slashes);
console.log(url.parse('RLP://site.com').slashes);
console.log(url.parse('RAP://site.com').slashes);
console.log(url.parse('L2TP://site.com').slashes);
console.log(url.parse('PPTP://site.com').slashes);
console.log(url.parse('SNMP://site.com').slashes);
console.log(url.parse('TFTP://site.com').slashes);

Output

Following is the output of the above program

The slashes property returns true because all the protocols in the above program require ASCII forward slashes.

true
true
true
true
true
true
true
true
true
true
true

Example

In this example, we are checking with some other protocols whether it requires two ASCII forward-slash (//) characters after the colon (:) or not.

console.log(url.parse('TCP://site.com').slashes);
console.log(url.parse('IP://site.com').slashes);
console.log(url.parse('UDP://site.com').slashes);
console.log(url.parse('POP://site.com').slashes);
console.log(url.parse('SMTP://site.com').slashes);
console.log(url.parse('FTP://site.com').slashes);
console.log(url.parse('HTTP://site.com').slashes);
console.log(url.parse('HTTPS://site.com').slashes);

Output

As we can see in the output below, the slashes property returns true because all the protocols in the above program require ASCII forward slashes.

true
true
true
true
true
true
true
true
nodejs_url_module.htm
Advertisements