-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_module.js
More file actions
28 lines (20 loc) · 799 Bytes
/
url_module.js
File metadata and controls
28 lines (20 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const url = require('url');
const myURL = new URL('https://www.youtube.com:8080/watch?v=fBNz5xF-Kx4');
//getting serialized url
console.log(myURL.href);
console.log(myURL.toString());
//host or root domain, gets port number as well
console.log(myURL.host);
//hostname, returns everything same as host except the port number
console.log('hostname: '+myURL.hostname);
//Pathname returns everthing between '/' and '?' in url
console.log('pathname: '+myURL.pathname);
//Serialized query..returns everything after '?' in the url
console.log(myURL.search);
//Get url parameters
console.log('parameters in url: '+myURL.searchParams);
//Add parameters
myURL.searchParams.append('abc', '123');
myURL.searchParams.append('lock', '345');
console.log(myURL.searchParams);
console.log(myURL.toString());