---
title: "getDomain"
description: "Extract the hostname from a URL string, returning the domain portion so you can compare, filter, or display the origin of a link."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-domain"
---
# getDomain

> Extract the hostname from a URL string, returning the domain portion so you can compare, filter, or display the origin of a link.

## Usage

`getDomain` extracts the hostname portion from a URL.

```ts
import { getDomain } from '@movk/core'

getDomain('https://sub.example.com/path') // 'sub.example.com'
getDomain('https://example.com:8080') // 'example.com'
```

## API

### `getDomain(url)`

Extract the domain from a URL.

### Parameters

**url** (`string`) *required*: The URL string.

### Returns

**returns** (`string`): The domain name, or an empty string if parsing fails.

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/parse.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
