showing results for - "url parser js node"
Amandine
18 Jan 2020
1const myURL = new URL('https://example.org:81/foo');
2console.log(myURL.hostname);
3// Prints example.org
4
5// Setting the hostname does not change the port
6myURL.hostname = 'example.com:82';
7console.log(myURL.href);
8// Prints https://example.com:81/foo
9
10// Use myURL.host to change the hostname and port
11myURL.host = 'example.org:82';
12console.log(myURL.href);
13// Prints https://example.org:82/foo