Tutorial Intro
Let's discover Popyt in less than 5 minutes.
Getting started
Get started by creating a new Node.JS project and running npm install popyt
.
Check out the
Click Fork in the top right, press CTRL+K
and type "environment" to set the YOUTUBE_API_KEY
environment variable, and then try Popyt right from your browser.
What you'll need
- A YouTube Data v3 API key:
- Complete steps 1-4 and copy your API key.
Retrieving public data
Retrieve public data from YouTube by directly using the YouTube class. Instantiate the class like this:
const { YouTube } = require('popyt')
const youtube = new YouTube(process.env.YOUTUBE_API_KEY)
It is not recommended to place an API key directly in your code. Instead, use an environment variable.
Here are a few examples of retrieving data, but check the documentation for everything else:
Get a video by ID:
const video = await youtube.getVideo('dQw4w9WgXcQ')
console.log(video.title)
You can do the same thing with playlists, channels, and comments by replacing Video with any of them.
Get a video by URL:
const video = await youtube.getVideo('https://youtube.com/watch?v=dQw4w9WgXcQ')
console.log(video.title)
Get a video by title (or similar title):
const video = await youtube.getVideo('never gonna give you up')
console.log(video.title)
Search videos:
const search = await youtube.searchVideos('never gonna give you up', { pageOptions: { maxPerPage: 25 } })
console.log(search.results.map(v => v.title).join('\n')) // titles of 25 beautiful videos