How to get a YouTube transcript in Node.js
Checked on 2026-11-18.
In JavaScript there are two practical routes to a YouTube transcript: an npm package that reads YouTube directly, and an HTTP API you call with fetch. Which one fits depends on where your code runs.
1. The youtube-transcript npm package
Free, no API key, and a one-line call.
// npm install youtube-transcript
import { YoutubeTranscript } from 'youtube-transcript';
const segments = await YoutubeTranscript.fetchTranscript('jNQXAC9IVRw');
console.log(segments.map((s) => s.text).join(' '));Where it breaks:
- In the browser. YouTube does not allow cross-origin requests to these pages, so the call has to run on a server.
- On cloud servers and serverless functions. YouTube blocks many data-centre IP addresses, so code that works locally can fail once deployed.
- Over time. Packages like this read an interface YouTube does not document, and they stop working when it changes until the package is updated.
2. A plain fetch call to an HTTP API
With Pipefetch a transcript is one HTTPS request, with nothing to install. It runs anywhere fetch does: Node.js 18 or newer, Vercel and Netlify functions, Cloudflare Workers.
const url = new URL('https://pipefetch.com/v1/youtube/transcript');
url.searchParams.set('video', 'https://www.youtube.com/watch?v=jNQXAC9IVRw');
const res = await fetch(url, {
headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY },
});
if (res.status === 404) {
console.log('No captions for this video'); // not charged
} else {
const { data } = await res.json();
console.log(data.text); // the whole transcript
for (const segment of data.segments) { // timed pieces
console.log(segment.start, segment.text);
}
}A request costs 1 credit, a video without captions costs nothing, and a new account has 100 free credits. Pass format set to srt or vtt for a ready subtitle file. The reference lists every parameter.
Keep the key off the client
Whichever API you use, do not put its key in code that ships to the browser, because anyone can read it there and spend your credits. Call the API from your server or a serverless function and return only the transcript to the page.
Why not the official YouTube Data API?
Its captions.download method only returns captions for videos you own or manage, and it requires OAuth. For other people's public videos it is not an option.
Try it with 100 free credits. No card, no Google Cloud project, no OAuth. Get an API key or read the docs.
APIs used in this guide
-
1 credit
YouTube Transcript API
The transcript of any public video with captions, as plain text, timestamped segments, SRT or WebVTT.
GET /v1/youtube/transcript -
1 credit
YouTube Search API
YouTube search results for a query, with the same sorting and filters the site offers.
GET /v1/youtube/search