Overview
Fast, no-browser YouTube transcript extraction for Node, serverless and Cloudflare Workers — with optional React components.
extract-youtube fetches the captions of any YouTube video straight from YouTube's own caption endpoints. There is no headless browser, no Puppeteer, and no YouTube Data API key — just fetch, which is why the same code runs in Node, Bun, AWS Lambda, Vercel Edge and Cloudflare Workers.
The package has three independent entry points:
| Entry point | What it is | Pulls in React? |
|---|---|---|
extract-youtube | The transcript API, formatters, proxy configs and the CLI | No |
extract-youtube/library | A video library with an admin API: in-memory or D1 storage, one HTTP handler, a typed client | No |
extract-youtube/react | A floating YouTube player, a synced-transcript modal, video grid and list components, and library admin screens | Yes (peer dependency) |
Import only what you need; the rest never ends up in your bundle. Everything runs on Cloudflare Workers, and the live demo shows the library, the grid, the floating player and the admin screens together, on the same server as these docs.
Install
npm install extract-youtubeOr run it once without installing:
npx extract-youtube dQw4w9WgXcQFor the React components, also install the peer dependencies:
npm install extract-youtube react react-dom lucide-reactQuick start
import { YouTubeTranscriptApi } from 'extract-youtube';
const api = new YouTubeTranscriptApi();
const transcript = await api.fetch('dQw4w9WgXcQ');
for (const snippet of transcript) {
console.log(`${snippet.start}s: ${snippet.text}`);
}Every snippet has text, start (seconds) and duration (seconds). transcript.toRawData() gives you the same as a plain array, ready for JSON.stringify.
What's in the box
- Transcripts — fetch, pick languages, list available tracks, translate, handle typed errors.
- Formatters — JSON, plain text, SRT, WebVTT, pretty-print and an article format.
- CLI —
extract-youtube <video-id> -f srtfrom any terminal. - Proxies — keep working when YouTube starts rate-limiting your server's IP.
- Deploy to Cloudflare — a transcript endpoint on Workers.
- Floating player and transcript modal — React UI for watching with synced captions.
- Video grid and list: cards, a grouped table and stacked playlists for browsing a video library.
- Library admin API, custom fields and admin components: store and curate that library, on D1 or in memory.
- Live demo: all of it running on the server that serves this site, on the YouTube tab of /demo.
Why this package
- Proven approach. A TypeScript port of the widely used Python
youtube-transcript-apicaption-fetching logic. - Serverless-first. No filesystem access, no native modules, nothing that needs a Node-only socket — so it fits Lambda, Vercel Edge and Workers.
- Typed end to end. Full TypeScript types and a typed error for every failure mode (
TranscriptsDisabled,NoTranscriptFound,IpBlocked, …). - Small. ESM and CJS builds, tree-shakeable, a handful of small dependencies.
Cite with an LLM
extractCiteLLM completes a webpage's full citation with one model call, scores every part, flags what needs review, reads author qualifications, and writes APA, MLA, Chicago, Harvard, IEEE and BibTeX.
Fetching transcripts
Fetch captions, choose languages, list available tracks, translate, and handle errors.