# youtube-video-id

> Extracts the YouTube video ID from a URL or string.

Latest version **1.0.5** (published 2025-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install youtube-video-id
pnpm add youtube-video-id
yarn add youtube-video-id
bun add youtube-video-id
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2025-09-19 |
| First published | 2016-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Mark |
| Maintainers | remarkablemark |
| Keywords | youtube, video, id, url, string |

## Links

- npm: https://www.npmjs.com/package/youtube-video-id
- Repository: https://github.com/remarkablemark/youtube-video-id
- Homepage: https://github.com/remarkablemark/youtube-video-id#readme
- Issues: https://github.com/remarkablemark/youtube-video-id/issues
- npm.io page: https://npm.io/package/youtube-video-id

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2025-09-19
- 1.0.4 — 2024-08-29
- 1.0.3 — 2023-11-08
- 1.0.2 — 2023-11-08
- 1.0.1 — 2023-09-10
- 1.0.0 — 2023-09-10
- 0.0.4 — 2023-09-09
- 0.0.3 — 2018-10-07
- 0.0.2 — 2017-07-15
- 0.0.1 — 2016-10-02

## README

# youtube-video-id

[![NPM](https://nodei.co/npm/youtube-video-id.png)](https://nodei.co/npm/youtube-video-id/)

[![NPM version](https://img.shields.io/npm/v/youtube-video-id.svg)](https://www.npmjs.com/package/youtube-video-id)
[![build](https://github.com/remarkablemark/youtube-video-id/actions/workflows/build.yml/badge.svg)](https://github.com/remarkablemark/youtube-video-id/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/remarkablemark/youtube-video-id/graph/badge.svg?token=PQL6PG63WG)](https://codecov.io/gh/remarkablemark/youtube-video-id)

:tv: Extract the YouTube video ID from a string or URL:

```
YouTubeVideoId(string)
```

[Replit](https://replit.com/@remarkablemark/youtube-video-id) | [JSFiddle](https://jsfiddle.net/remarkablemark/93fkfb22/) | [Examples](https://github.com/remarkablemark/youtube-video-id/tree/master/examples)

## Installation

[NPM](https://www.npmjs.com/package/youtube-video-id):

```sh
npm install youtube-video-id
```

[Yarn](https://yarnpkg.com/package?name=youtube-video-id):

```sh
yarn add youtube-video-id
```

[CDN](https://unpkg.com/browse/youtube-video-id/):

```html
<script src="https://unpkg.com/youtube-video-id@latest/dist/youtube-video-id.min.js"></script>
```

## Usage

### Server

Import with ES Modules:

```js
import YouTubeVideoId from 'youtube-video-id';
```

Or require with CommonJS:

```js
const YouTubeVideoId = require('youtube-video-id').default;
```

Extract YouTube video ID from URL or string:

```js
YouTubeVideoId('https://www.youtube.com/watch?v=X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
YouTubeVideoId('https://youtu.be/X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
YouTubeVideoId('X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
```

### Client

Load script:

```html
<script src="https://unpkg.com/youtube-video-id@latest/dist/youtube-video-id.min.js"></script>
```

Extract YouTube video ID from URL or string:

```html
<script>
  const videoId = YouTubeVideoId('https://www.youtube.com/watch?v=F2uovvU-dLA');
  console.log(videoId);
</script>
```

## Migration

### v1

Migrate to TypeScript and build ESM. CommonJS import now requires the `.default` key:

```js
const YouTubeVideoId = require('youtube-video-id').default;
```

## Release

Release is automated with [Release Please](https://github.com/googleapis/release-please).

## License

[MIT](https://github.com/remarkablemark/youtube-video-id/blob/master/LICENSE)

---
_Source: https://npm.io/package/youtube-video-id · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
