How to get the host (root domain) of a URL in Node.js

1 Answer

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

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

console.log(testurl.host);
  
  
       
/*
run:
     
www.website.com
   
*/

 



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