Skip to main content

Tutorial Intro

Let's discover Popyt in less than 5 minutes.

Getting started​

Get started by creating a new Node.JS project and running

OR

Check out the CodeSandbox for a quick example that you can run online and fork on GitHub.
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​

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)
TAKE CARE

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

Retrieving private data​

See OAuth.