What is yt-search?
The yt-search npm package is a simple and efficient tool for searching YouTube videos, channels, and playlists. It provides an easy-to-use interface for fetching YouTube search results and metadata.
What are yt-search's main functionalities?
Search for Videos
This feature allows you to search for YouTube videos based on a query string. The code sample demonstrates how to search for videos related to 'Node.js tutorial' and log the results.
const ytSearch = require('yt-search');
async function searchVideos(query) {
const result = await ytSearch(query);
return result.videos;
}
searchVideos('Node.js tutorial').then(videos => {
console.log(videos);
});
Search for Channels
This feature allows you to search for YouTube channels based on a query string. The code sample demonstrates how to search for channels related to 'Tech channels' and log the results.
const ytSearch = require('yt-search');
async function searchChannels(query) {
const result = await ytSearch(query);
return result.channels;
}
searchChannels('Tech channels').then(channels => {
console.log(channels);
});
Search for Playlists
This feature allows you to search for YouTube playlists based on a query string. The code sample demonstrates how to search for playlists related to 'Music playlists' and log the results.
const ytSearch = require('yt-search');
async function searchPlaylists(query) {
const result = await ytSearch(query);
return result.playlists;
}
searchPlaylists('Music playlists').then(playlists => {
console.log(playlists);
});
Get Video Details
This feature allows you to get detailed information about a specific YouTube video using its video ID. The code sample demonstrates how to fetch and log details for the video with ID 'dQw4w9WgXcQ'.
const ytSearch = require('yt-search');
async function getVideoDetails(videoId) {
const result = await ytSearch({ videoId });
return result;
}
getVideoDetails('dQw4w9WgXcQ').then(video => {
console.log(video);
});
Other packages similar to yt-search
youtube-search
The youtube-search package provides similar functionality for searching YouTube videos. It allows you to search for videos and retrieve metadata, but it may require an API key for access, unlike yt-search which does not.
ytsr
The ytsr package is another alternative for searching YouTube content. It offers more advanced search capabilities and filtering options compared to yt-search, but it also requires more configuration.
simple-youtube-api
The simple-youtube-api package provides a more comprehensive interface for interacting with the YouTube Data API. It supports searching for videos, channels, and playlists, as well as managing YouTube resources, but it requires an API key.
yt-search - simple youtube search API and CLI

Simple to use
CLI usage
npm install -g yt-search
yt-search superman theme
API usage
const ytSearch = require( 'yt-search' )
ytSearch( 'superman theme', function ( err, r ) {
if ( err ) throw err
const videos = r.videos
const playlists = r.playlists
const accounts = r.accounts
const firstResult = videos[ 0 ]
console.log( firstResult )
} )
Output
{
title: 'Superman Theme',
url: '/watch?v=e9vrfEoc8_g',
videoId: 'e9vrfEoc8_g',
seconds: 253,
timestamp: '4:13',
duration: {
toString: [Function: toString],
seconds: 253,
timestamp: '4:13'
},
ago: '8 years ago',
views: 29127516
}
About
Simple api to search youtube results.
Why
Not sure..
How
Using HTTP requests and parsing the results with cheerio.
CLI interactive mode with node-fzf
API
const opts = {
query: 'superman theme',
pageStart: 1, // first youtube page result
pageEnd: 3 // up until page 3
}
ytSearch( opts, function ( err, r ) {
if ( typeof opts === 'string' ) {
opts = {
query: opts,
pageStart: 1,
pageEnd: 3
}
}
// etc
} )
Installation
npm install yt-search
npm install -g yt-search