How to get YouTube comments in Node.js
Checked on 2026-11-24.
For comments, the official YouTube Data API is a good route from Node.js: Google's googleapis package calls commentThreads.list with an API key, and the daily quota goes a long way. Without a Google Cloud project there are two more: the youtubei.js library, which reads YouTube's internal API, and an HTTP API you call with fetch.
1. The YouTube Data API with googleapis
You need a Google Cloud project with the YouTube Data API enabled and an API key. Reading public comments needs no OAuth: the getting-started page says that for list methods "unauthorized requests only retrieve public data". The client is set up the way the googleapis README shows for an API key, and the parameters are those of commentThreads.list:
// npm install googleapis
const { google } = require('googleapis');
const youtube = google.youtube({ version: 'v3', auth: process.env.YOUTUBE_API_KEY });
async function main() {
let pageToken;
do {
const res = await youtube.commentThreads.list({
part: ['snippet'],
videoId: 'jNQXAC9IVRw',
maxResults: 100, // 1 to 100; 20 when left out
order: 'relevance', // or 'time', the default
textFormat: 'plainText', // 'html' is the default
pageToken,
});
for (const thread of res.data.items ?? []) {
const comment = thread.snippet.topLevelComment.snippet;
console.log(comment.authorDisplayName, comment.likeCount, comment.textDisplay);
}
pageToken = res.data.nextPageToken;
} while (pageToken);
}
main().catch(console.error);"A call to this method has a quota cost of 1 unit", and the default allowance is "10,000 units per day combined" for every method except search and uploads, so reading every thread of a video costs one unit per hundred. A video with comments turned off fails with 403 and the reason commentsDisabled. Each thread's replies are "only a subset" of its replies: for all of them the documentation sends you to comments.list. When the quota runs out, the guide to the quotaExceeded error explains what to do.
Where it stops: mostly at setup and at the package. The latest googleapis, version 190.0.0, declares Node.js 22 or newer on npm, and its README says the libraries "are considered complete and are in maintenance mode". To reduce start-up time, the README offers each API as a submodule of its own; for YouTube that is npm install @googleapis/youtube. The data itself is the most complete of the three routes: every thread, newest or most relevant first, with exact dates in publishedAt.
2. youtubei.js, without a key
YouTube.js, published on npm as youtubei.js, is "A JavaScript client for YouTube's internal API". It needs no key and no Google project. The method and fields below are from its API documentation and source:
// npm install youtubei.js
import { Innertube } from 'youtubei.js';
const youtube = await Innertube.create();
let page = await youtube.getComments('jNQXAC9IVRw', 'TOP_COMMENTS'); // or 'NEWEST_FIRST'
for (let pages = 0; pages < 3; pages++) {
for (const thread of page.contents) {
const comment = thread.comment;
console.log(comment?.author?.name, comment?.like_count, comment?.content?.toString());
}
if (!page.has_continuation) break;
page = await page.getContinuation();
}Counts such as like_count arrive as text, and published_time is text as well, not a timestamp.
Where it breaks: when YouTube changes its internal API, until the library catches up. In July 2026 getComments() began to crash for some videos on version 17.2.0 (issue 1204, since closed), and one user wrote: "This started happening recently without any code changes on my side." Keep it updated; the latest version on 2026-11-24 was 18.3.0. In the browser it does not work on its own: its documentation says "To use YouTube.js in the browser, you must proxy requests through your own server." Its README adds that the project "is not affiliated with, endorsed, or sponsored by YouTube".
3. An HTTP API, with fetch or the npm client
With Pipefetch the top or the newest comments of a video are one HTTPS request with one key, from any server, with no Google project and no YouTube quota. A plain fetch call:
const url = new URL('https://pipefetch.com/v1/youtube/comments');
url.searchParams.set('video', 'jNQXAC9IVRw');
url.searchParams.set('limit', '100');
url.searchParams.set('sort', 'top'); // or 'newest'
const res = await fetch(url, {
headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY },
signal: AbortSignal.timeout(90_000),
});
if (res.status === 404) {
console.log('No comments, comments turned off, or no such video'); // not charged
} else if (!res.ok) {
throw new Error(`Pipefetch answered ${res.status}`);
} else {
const { data } = await res.json();
console.log(data.totalComments, 'comments in total');
for (const comment of data.comments) console.log(comment.author.name, comment.likeCount, comment.text);
}The npm client, pipefetch, has a method for it:
// npm install pipefetch
import Pipefetch, { NotFoundError } from 'pipefetch';
const pf = new Pipefetch(); // reads PIPEFETCH_API_KEY
try {
const { comments } = await pf.comments('jNQXAC9IVRw', { limit: 40, sort: 'newest' }); // 2 credits
for (const c of comments) console.log(c.publishedText, c.replyCount, c.isPinned, c.text);
} catch (error) {
if (error instanceof NotFoundError) console.log(error.code); // comments_disabled, for example: not charged
else throw error;
}One limit to know: it returns up to 100 comments per video, the top ones or the newest ones, and no further pages. They are top-level comments, each with its replyCount and flags for pinned and creator-hearted comments; replies themselves are not returned. The date is YouTube's own text, such as "6 years ago", not a timestamp. It costs 1 credit per started 20 comments, so 100 comments are 5 credits, and a video with comments turned off answers 404 and costs nothing. The reference lists every field.
Where it stops: at that page of 100 and at replies. It is not an official API, and Pipefetch is not affiliated with YouTube or Google.
Which one should you use?
| You need | Use |
|---|---|
| Every comment of a video, replies, or exact dates | The official API with googleapis |
| Comments without a key, from a script you keep up to date | youtubei.js |
| The top or newest comments of many videos, from a server, without a Google Cloud project | An HTTP API such as Pipefetch |
Comments are personal data
A comment comes with its author's public name and channel. Under laws such as the GDPR that is personal data, whichever route you used to fetch it. Keep only what your purpose needs, and do not publish lists of commenters. For the same task in Python, see YouTube comments in Python; for transcripts in JavaScript, YouTube transcripts in Node.js.
Try it with 100 free credits. No card needed. No Google Cloud project or OAuth. Get an API key or read the docs.
APIs used in this guide
-
1 credit
YouTube Video API
Exact views, likes and comment count, description, tags, chapters and channel for one video.
GET /v1/youtube/video -
1 credit / 20
YouTube Comments API
Top or newest comments of a video with likes, reply counts, pinned and hearted flags.
GET /v1/youtube/comments
More YouTube guides
- How to get a YouTube transcript in Python
- How to get a YouTube transcript in Node.js
- YouTube API quota exceeded: what the error means and how to fix it
- How to find a YouTube channel ID from a handle or URL
- How to download YouTube subtitles as SRT or VTT
- youtube-transcript-api RequestBlocked or IpBlocked: why it happens and how to fix it
- How to get YouTube comments in Python
- How to search YouTube from Python
- How to list a YouTube channel's videos in Python
- How to summarize a YouTube video with an LLM in Python
- How to get YouTube transcripts and video stats in Google Sheets
- How to get YouTube video views and likes in Python
- How to get YouTube transcripts in n8n, Make and Zapier
- LangChain YoutubeLoader fails on a server: why, and a loader that works
- How to get a YouTube channel's subscriber count in Python
- How to give Claude or Cursor access to YouTube (MCP server)
- How to analyze YouTube comments with an LLM in Python
- How to list a YouTube channel's Shorts in Python
- How to search YouTube from JavaScript
Guides for other sources
Every source
- How to get an Instagram follower count in Python
- Instagram Basic Display API alternatives: what to use after the shutdown
- Instaloader 401 Unauthorized, 429 and "Login required": what to do
- How to calculate an Instagram engagement rate in Python
- How to get an Instagram follower count in Node.js
- How to get Instagram follower counts in Google Sheets
- How to get Instagram Reel views in Python
Websites
- Clearbit Logo API alternatives: get a company logo from its domain
- How to extract email addresses from a website in Python
- How to turn a web page into Markdown in Python
- How to detect what a website is built with, in Python
- How to get the contact emails and phone numbers of websites in Google Sheets
- How to build a LangChain tool that reads web pages and searches Google
- How to turn a web page into Markdown in JavaScript for RAG
- How to extract social media links from a website in Python
- How to get a website's favicon in Python
- How to check robots.txt in Python before you fetch a page
TikTok
- How to get a TikTok video's views and likes in Python
- How to get the comments of a TikTok video in Python
- How to get a TikTok follower count in Python
- TikTok Research API: who can get access, and what to do if you cannot
- How to get TikTok video views, likes and shares in Node.js
- How to get TikTok views, likes and follower counts in Google Sheets
- How to get a Facebook Page's posts without app review
- Is there a Facebook Marketplace API?
- Facebook Groups API alternatives after its removal in 2024
- How to get a Facebook Page's follower count and contact details in Python
- How to get Google search results in Python
- pytrends 429 TooManyRequestsError: what it means and what to do
- How to get Google Trends data in Python
- Why is Wyoming first in Google Trends?
- How to get Google search results in Node.js
- How to get Google search results into Google Sheets
- How to give an LLM live Google results with tool calling
Threads
- How to get LinkedIn company data in Python
- How to search LinkedIn jobs from Python
- How to get a LinkedIn company page's latest posts in Python