npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fetchlayer/youtube

v0.2.0

Published

Official FetchLayer SDK for YouTube data. Scrape YouTube comments, reply threads, and transcripts from any video with JavaScript and TypeScript.

Readme

YouTube Comments Scraper & API Client for JavaScript / TypeScript

npm license types

The official JavaScript & TypeScript SDK for the FetchLayer YouTube API.

Scrape YouTube comments. Pull reply threads. Extract video transcripts. Get likes, authors, and dates. All as clean JSON from a single API — no Google Cloud project, no OAuth, no HTML parsing.

Open-source SDK, hosted API. This package is MIT-licensed. The API requires a free FetchLayer API key — no subscriptions, no contracts, no lock-in. Pay only for what you use.


Install

npm install @fetchlayer/youtube
pnpm add @fetchlayer/youtube
yarn add @fetchlayer/youtube

Get your API key

  1. Go to fetchlayer.dev
  2. Sign in with your email
  3. Copy your API key from the dashboard

That's it. No credit card. No trial expiration. You get free requests to start, then pay-as-you-go when you need more.

Quick start

import { FetchLayerYoutube } from "@fetchlayer/youtube";

const youtube = new FetchLayerYoutube({
  apiKey: process.env.FETCHLAYER_API_KEY!,
});

// Scrape comments from any YouTube video
const comments = await youtube.getComments({
  videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  sort: "top",
  pages: 2,
});

console.log(comments);

That's 4 lines to get structured YouTube comment data. No Google Cloud setup, no OAuth dance, no broken scrapers.


Why use this instead of scraping YouTube yourself

| Problem | FetchLayer | | --- | --- | | YouTube blocks your IP | We handle rotation and resilience | | HTML structure changes break your parser | You get stable JSON | | YouTube Data API needs a Google Cloud project + quota | Simple Bearer token, no quota | | Maintaining scraping infra is a full-time job | npm install and done | | You need comments, replies, AND transcripts | Three endpoints, one SDK |


All methods

const youtube = new FetchLayerYoutube({ apiKey });

| Method | What it does | | --- | --- | | youtube.getComments(params) | Scrape top-level comments from a video | | youtube.getCommentReplies(params) | Fetch replies to a specific comment | | youtube.getTranscript(params) | Extract video transcript with timestamps |


Examples

Scrape top comments from a video

const response = await youtube.getComments({
  videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  sort: "top", // "top" (most liked) or "newest"
  pages: 3,    // scroll for more comments
});

for (const comment of response.comments ?? []) {
  console.log(`${comment.username}: ${comment.comment}`);
  console.log(`  ${comment.likes} likes · ${comment.date}`);
}

Get the latest discussion

const response = await youtube.getComments({
  videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  sort: "newest",
  pages: 5,
});

Fetch replies to a specific comment

const thread = await youtube.getCommentReplies({
  videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  commentId: "Ugz...",
  depth: 2,
});

console.log(thread.comment);
for (const reply of thread.nestedReplies ?? []) {
  console.log(`  ↳ @${reply.username}: ${reply.comment}`);
}

Extract a video transcript

const transcript = await youtube.getTranscript({
  videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  language: "en",
});

console.log(transcript.text);
for (const segment of transcript.segments ?? []) {
  console.log(`[${segment.start}s] ${segment.text}`);
}

Error handling

import { FetchLayerYoutube, FetchLayerError } from "@fetchlayer/youtube";

try {
  const comments = await youtube.getComments({ videoUrl: "https://..." });
} catch (err) {
  if (err instanceof FetchLayerError) {
    console.error(err.status); // 401, 429, etc.
    console.error(err.message); // Human-readable error from the API
  }
}

Configuration

const youtube = new FetchLayerYoutube({
  apiKey: "your-key",     // Required
  baseUrl: "...",         // Default: https://api.fetchlayer.dev/youtube
  timeoutMs: 120000,      // Default: 120s
  fetch: customFetch,    // Default: global fetch (Node 18+)
});

What this package is

  • Zero dependencies — uses native fetch, nothing else
  • Dual build — ESM + CommonJS, works everywhere
  • Fully typed — TypeScript declarations included
  • Tiny — under 6 KB bundled
  • Open source — MIT license, contributions welcome

How it works

You call FetchLayer → FetchLayer returns structured YouTube comment data as JSON → you use it however you want.

No YouTube account needed. No Google Cloud project. No scraping infrastructure on your end.


Pricing

| | | | --- | --- | | Free tier | Included with every account — start building immediately | | Pay-as-you-go | $1.99 per 1,000 requests. Credits never expire. | | Subscriptions | Available for heavy use — predictable pricing at scale | | Rate limits | None |

No credit card required to start. No monthly commitment. No overages. Get your API key →


Use cases

  • Audience research — find what viewers ask, praise, and complain about in the comments
  • Content research — discover recurring questions and content requests for your next video
  • Competitive intelligence — monitor comments on competitor videos and launches
  • Sentiment analysis — pull comments and run NLP on real viewer opinions
  • Community management — track feedback and engagement across your channel
  • AI agents — give your LLM real-time YouTube context via FetchLayer's MCP server

Links

| | | | --- | --- | | Get API key | fetchlayer.dev/signin | | Product page | fetchlayer.dev/youtube-comments-api | | Homepage | fetchlayer.dev | | npm | @fetchlayer/youtube | | Issues | GitHub Issues |


License

MIT — see LICENSE.