How to get the hostname of a URL in Node.js

1 Answer

0 votes
const url = require('url');

const testurl = new URL('https://www.website.com:8080/index.html?id=8372&age=43')

console.log(testurl.host);
console.log(testurl.hostname);
  

       
/*
run:
     
www.website.com:8080
www.website.com
   
*/

 



answered Mar 10, 2020 by avibootz
edited Mar 10, 2020 by avibootz

Related questions

3 answers 450 views
1 answer 306 views
1 answer 333 views
333 views asked Mar 10, 2020 by avibootz
1 answer 377 views
1 answer 304 views
304 views asked Mar 10, 2020 by avibootz
3 answers 538 views
...