Examples & Code to Get Host, Hostname & Port
Example URL: http://localhost:3000 // HOST Question: What is "Host" in the above URL? Answer: "localhost:3000" Syntax to get Host: window.location.host // HOSTNAME Question: What is "Hostname" in the above URL? Answer: "localhost" Syntax to get Hostname: window.location.hostname // PORT Question: What is "Port" in the above URL? Answer: "3000" Syntax to get Port number: window.location.port
For more information regarding the browser support for this host, hostname & port you can refer its MDN web doc’s page.