Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YouTube Comments Scraper & API Client for JavaScript / TypeScript

npm license types

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

Scrape YouTube comments. Pull nested replies. 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",
  depth: 1,
  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 AND nested replies One endpoint, one SDK

All methods

const youtube = new FetchLayerYoutube({ apiKey });
Method What it does
youtube.getComments(params) Scrape comments and nested replies from a video

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"
  depth: 1,    // include one level of replies
  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,
});

Walk nested replies

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

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

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.

About

YouTube Comments Scraper & API Client for JavaScript and TypeScript. Scrape YouTube comments and nested replies as structured JSON. Zero deps, fully typed, MIT licensed.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages