Docs

URL.prototype.origin

The origin of the URL (read-only).

Example

let url = new URL("https://example.com:8080/path?query=value#fragment")
url.origin
"https://example.com:8080"
let url = new URL("http://localhost:3000/api")
url.origin
"http://localhost:3000"