Muhammad Umer
Muhammad Umer

Reputation: 18097

In Nodejs, how to extract just domain.com from url?

Given urls like these

www.yahoo.com
support.abc.com/whatever?a=1
clear.com
biz.co.uk/how

How do I get

yahoo.com
abc.com
clear.com
biz.co.uk

Url.parse.hostname returns url including subdomain and how would nodejs or browser know biz is domain name not subdomain

Upvotes: 1

Views: 1731

Answers (1)

hobbs
hobbs

Reputation: 239910

and how would nodejs or browser know biz is domain name not subdomain

Using the Public Suffix List information, for example through a library like tldjs for JavaScript.

Upvotes: 2

Related Questions