Node.js urlObject.slashes is a legacy property that indicates whether a parsed URL contains two forward slashes (//) after its protocol. It is part of the object by url.parse() and is used when working with the older URL API.
urlObject.slashesis a boolean property that represents the presence of double slashes after the protocol.- It is set to
truewhen the URL contains//after the protocol. - It is set to
falsewhen the URL does not include double slashes.
Syntax
urlObject.slashesWhere
- urlObject : It represents the object returned by the
url.parse()method. - slashes : It is a property of the
urlObjectthat indicates the presence of//after the protocol.
Return Value: The urlObject.slashes property returns true if two ASCII value forward slashes are required, otherwise, it returns false.
Example 1:
// Importing the module 'url-parse'
const parse = require('url-parse');
// Use command 'npm install url-parse' in
// command prompt to import this module
const url = parse('www.geeksforgeeks.org');
// Display result in console
console.log(url.slashes);
Output
falseExample 2:
// Importing the module 'url-parse'
const parse = require('url-parse'),
url = parse('https://example.com/geek/login');
// Display the result in console view
console.log(url.slashes)
Output
trueUse Cases of urlObject.slashes API
- It is used to check whether a URL includes
//after the protocol. - It helps in correctly reconstructing or formatting URLs in legacy code.
- It is useful when handling or validating URLs parsed using
url.parse(). - It assists in maintaining compatibility with older Node.js URL handling logic.
Reference: https://nodejs.org/api/url.html#url_urlobject_slashes