url
const url = require('url');
const parsedUrl = url.parse('https://example.com:8080/path/to/file?query=string#fragment');
console.log(parsedUrl.protocol); // 'https:'
console.log(parsedUrl.host); // 'example.com:8080'
console.log(parsedUrl.pathname); // '/path/to/file'
console.log(parsedUrl.query); // 'query=string'
console.log(parsedUrl.fragment); // 'fragment'const url = require('url');
const myUrl = new URL('https://example.com:8080/path/to/file?query=string#fragment');
console.log(myUrl.toString()); // 'https://example.com:8080/path/to/file?query=string#fragment'const url = require('url');
const myUrl = new URL('https://example.com:8080/path/to/file?query=string#fragment');
myUrl.protocol = 'http:';
console.log(myUrl.toString()); // 'http://example.com:8080/path/to/file?query=string#fragment'