How to search YouTube from JavaScript

Checked on 2026-11-24.

From JavaScript a YouTube search is one GET request to the Data API's search.list, made from Node.js or, with the key kept on a server, for a web page. The limit to plan around is the quota: by default a project gets 100 search calls a day, and each returns at most 50 results. Below: the request with fetch and with Google's googleapis package, what the quota means in practice, and an HTTP API without the daily cap.

1. search.list with fetch

You need a Google Cloud project with the YouTube Data API v3 enabled and an API key. Searching public videos needs no OAuth: the getting-started page says that "unauthorized requests only retrieve public data", and its examples pass the key as key=YOUR_API_KEY. The address and parameters are those of the search.list reference. Save this as search.mjs and run it with Node.js 18 or newer:

JavaScript
const url = new URL('https://www.googleapis.com/youtube/v3/search');
url.search = new URLSearchParams({
  part: 'snippet',
  q: 'web scraping tutorial',
  type: 'video',             // channel, playlist, video; the default is all three
  maxResults: '25',          // 0 to 50, the default is 5
  order: 'relevance',        // date, rating, title, videoCount, viewCount
  key: process.env.YOUTUBE_API_KEY,
});

const res = await fetch(url);
if (!res.ok) throw new Error('search.list answered ' + res.status);
const page = await res.json();
for (const item of page.items) {
  console.log(item.id.videoId, item.snippet.publishedAt, item.snippet.title);
}

Other filters from the reference: publishedAfter (an RFC 3339 date-time), regionCode (a two-letter country code), relevanceLanguage, and videoDuration, where short means "less than four minutes long" and long "longer than 20 minutes". Further pages come with pageToken set to the nextPageToken of the answer.

A result is a search result resource: the ID, and a snippet with publish time, channel ID and name, title, description, thumbnails and liveBroadcastContent. It has no view count and no duration. For those, pass the IDs to videos.list:

JavaScript
const ids = page.items.map((item) => item.id.videoId).join(',');
const details = new URL('https://www.googleapis.com/youtube/v3/videos');
details.search = new URLSearchParams({ part: 'statistics,contentDetails', id: ids, key: process.env.YOUTUBE_API_KEY });
const videos = await (await fetch(details)).json();
for (const video of videos.items) {
  console.log(video.id, video.statistics.viewCount, video.contentDetails.duration);   // duration such as PT15M33S
}

2. The googleapis package

Google's Node.js client wraps the same request. This combines the README's API-key example with the search.list call of the library's own YouTube sample:

JavaScript
// npm install googleapis
const { google } = require('googleapis');

const youtube = google.youtube({ version: 'v3', auth: process.env.YOUTUBE_API_KEY });

async function main() {
  const res = await youtube.search.list({
    part: 'snippet',
    q: 'web scraping tutorial',
    type: 'video',
    maxResults: 25,
  });
  for (const item of res.data.items) {
    console.log(item.id.videoId, item.snippet.title);
  }
}

main().catch(console.error);

Know its status before you build on it: the README says these libraries "are considered complete and are in maintenance mode", with critical bugs and security issues fixed but no new features. Google also publishes the YouTube client on its own as @googleapis/youtube, if you would rather not install the whole package. For one GET request, fetch needs no dependency at all.

What 100 searches a day means

The reference states the cost plainly: "100 calls per day. A call to this method has a quota cost of 1 unit in the Search Queries quota bucket." Searches are counted apart from everything else, a change the revision history announced on 1 June 2026: a project has "a default quota allocation of 100 search.list calls, 100 videos.insert calls, and 10,000 units per day combined for all other endpoints", and Google adds that the default is "subject to change". In practice:

  • Every page is a call. With maxResults at 50, a project sees at most 5,000 search results a day, and one query paged ten deep uses a tenth of the day.
  • Mistakes count. "All API requests, including invalid requests, incur at least a one-point quota cost."
  • Details are cheap. videos.list costs 1 unit from the 10,000, so adding view counts to each page of results does not touch the search bucket.
  • More is possible. Google takes requests for a higher quota through its quota extension request form.

Older tutorials say a search costs 100 units of the 10,000; the documentation now puts searches in their own bucket at 1 unit each. When that bucket is empty, the guide to the quota exceeded error explains what to do.

In the browser: keep the key on a server

An API key in code that ships to the browser can be read by anyone who opens your page, and every search made with it comes out of your project's 100. Google's guidance on API keys warns that "Publicly exposing your API keys can lead to unexpected charges on your account or unauthorized access to your data", and recommends this pattern: "The client should pass requests to the server, which can add the credential and issue the request." Put the search behind a small endpoint of your own, and restrict the key in the Google Cloud console as well.

3. An HTTP API without the daily cap

With Pipefetch a search is one HTTPS request, and each result already carries its view count, duration and channel. The same rule about the key applies: call it from your server.

JavaScript
const url = new URL('https://pipefetch.com/v1/youtube/search');
url.search = new URLSearchParams({
  q: 'web scraping tutorial',
  limit: '20',            // 1 to 40
  sort: 'relevance',      // popularity, newest, mostViewed
  uploaded: 'month',      // hour, today, week, month, year
});

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 results'); // not charged
} else if (res.ok) {
  const { data } = await res.json();
  for (const video of data.results) {
    console.log(video.viewCount, video.durationSeconds, video.channel.name, video.title);
  }
}

type switches to short, channel, playlist or all; country and lang set where and in which language the search is run. Each result has its type, ID, address, title, description, publishedAt, durationSeconds, viewCount, position and channel. publishedAt can be worked out from a label such as "4 years ago", in which case publishedAtPrecision is estimated. The npm package pipefetch makes the same request with pf.search('web scraping tutorial', { limit: 20 }). The reference lists every parameter and field.

Where it stops: up to 40 results per search and no further pages, so it is the top of a search, not a deep crawl. A search costs 1 credit whatever the number of results, one that finds nothing answers 404 and costs nothing, and there is no daily cap. Most requests take 2 to 9 seconds. It is not an official API, and Pipefetch is not affiliated with YouTube or Google. A new account has 100 free credits and needs no card. The same search from Python is in the guide to searching YouTube from Python.

Which one should you use?

SituationUse
A few dozen searches a day, and you already have a Google Cloud projectsearch.list with fetch
An app that already uses Google's Node.js client for other APIsThe googleapis package
Results deeper than 40, through pagessearch.list, within its 100 calls
Hundreds of searches a day, or view counts in the same answerAn HTTP API such as Pipefetch

Try it with 100 free credits. No card needed. No Google Cloud project or OAuth. Get an API key or read the docs.

Every source

Instagram

Websites

TikTok

Facebook

Google

Threads

LinkedIn

App stores

Steam

X

Pinterest

Airbnb

Real estate

Keywords

Job boards

Eventbrite

Shopify stores

Public tenders

All guides