What You'll Learn
- • Setting up your development environment
- • Installing the required HTTP client
- • Authenticating with the ScrapeCreators API
- • Making requests to YouTube
- • Handling responses and errors
- • Best practices for production use
Extract video data from YouTube
Learn how to scrape YouTube videos using Node.js. This comprehensive guide will walk you through the entire process, from setup to implementation.
First, you'll need a ScrapeCreators API key to authenticate your requests.
Sign up at app.scrapecreators.com to get your free API key with 100 requests.
Make sure you have the following installed:
Axios is a promise-based HTTP client for Node.js
npm install axios
Now let's make a request to the YouTube API using Node.js. Replace YOUR_API_KEY
with your actual API key.
import axios from 'axios';
const API_KEY = 'YOUR_API_KEY';
async function scrape() {
try {
const response = await axios.get(`https://api.scrapecreators.com/v1/youtube/video?url=example_value&get_transcript=example_value`, {
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
console.log('Response:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
// Usage
scrape();
This endpoint accepts the following parameters:
url
Required(string)YouTube video or short URL
get_transcript
Optional(boolean)Get transcript of the video
Execute your script to test the API connection. You should see a JSON response with YouTube videos data.
✅ Success: You should receive a structured JSON response containing the requested data.
Here's an example of the JSON response you'll receive:
{
"id": "Y2Ah_DFr8cw",
"thumbnail": "https://img.youtube.com/vi/G6VTenw0S7o/maxresdefault.jpg",
"type": "video",
"title": "Inside the NBA: Chuck Trolls Jussie Smollett \"Do not commit crimes with checks, use cash!\"",
"description": "Description here",
"commentCountText": "347",
"commentCountInt": 347,
"likeCountText": "3.8K",
"likeCountInt": 3,
"viewCountText": "358,277",
"viewCountInt": 358277,
"publishDateText": "Feb 22, 2019",
"publishDate": "2019-02-22T00:00:00.000Z",
"channel": {
"id": "UCWH3hing1Qb4LnkRfQdxsxQ",
"url": "https://www.youtube.com/@afroballer8906",
"handle": "afroballer8906",
"title": "Afroballer"
},
"durationMs": 1670000,
"durationFormatted": "00:27:50",
"watchNextVideos": [
{
"id": "fRfkvQwf9Po",
"title": "Inside the NBA funniest moments of all time",
"thumbnail": "https://i.ytimg.com/vi/fRfkvQwf9Po/hqdefault.jpg?sqp=-oaymwFACKgBEF5IWvKriqkDMwgBFQAAiEIYAdgBAeIBCggYEAIYBjgBQAHwAQH4Af4JgALQBYoCDAgAEAEYfyBHKCgwDw==&rs=AOn4CLAnLkcTjwH2egq1U823zjwxx_63DA",
"channel": {
"title": "Beyond NBA",
"url": "https://www.youtube.com/@beyond-NBA",
"handle": "beyond-NBA",
"id": "UCPGhgqNOGTj1o1qilS6K8mA"
},
"publishDateText": "5 years ago",
"publishDate": "2020-02-27T18:26:04.534Z",
"viewCountText": "7,913,223 views",
"viewCountInt": 7913223,
"lengthText": "19:13",
"videoUrl": "https://www.youtube.com/watch?v=fRfkvQwf9Po"
}
],
"keywords": [
"charles barkley",
"inside the nba"
],
"transcript": [
{
"text": "it was a a lead of 13 for the Rockets up",
"startMs": "0",
"endMs": "5759",
"startTimeText": "0:00"
},
{
"text": "to six by halftime 5852",
"startMs": "5759",
"endMs": "8460",
"startTimeText": "0:05"
},
{
"text": "welcome everybody American Express",
"startMs": "8460",
"endMs": "10200",
"startTimeText": "0:08"
},
{
"text": "that team man he's a guy who was",
"startMs": "39239",
"endMs": "40890",
"startTimeText": "0:39"
}
],
"transcript_only_text": "it was a a lead of 13 for....play okay the Lakers will not make the playoffs the Kings will is the latest position go ahead Kenny I cannot leave you chuck here we caster do payable to answer a rattle check check never break America America let me just tell you something is that do not commit crimes with check come on man you cannot if you're gonna break the law I do not write a check because you write a check that what I never used ATM now you can only I heard you could only get $200 out of the holes oh stop America America you go hot write checks when you commit illegal activity I cannot believe that we completed we touch them all right there circle the bag he just said he punch every pillow I wasted all that damn town of money you know what you should have been was bad that's what I'm really amazing neighborhood Charles"
}
Check that your response includes the expected fields:
id
(string)thumbnail
(string)type
(string)title
(string)description
(string)Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Never expose your API key in client-side code. Use environment variables and secure key management practices.
When scraping multiple videos, consider batching requests to maximize throughput while staying within rate limits.
Use asynchronous processing in Node.js to handle multiple requests concurrently and improve overall performance.
Analyze YouTube videos to understand market trends, competitor analysis, and audience insights.
Track performance metrics, engagement rates, and content trends across YouTube videos.
Identify potential customers and business opportunities throughYouTube data analysis.
Check your API key is correct and properly formatted in the x-api-key header.
You ran out of credits and need to buy more.
The resource might not exist or be private.
Temporary server issue. Implement retry logic with exponential backoff.
ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.
There is no rate limit! So you can scrape as fast as you want!
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Yes! This tutorial focuses on core Node.js HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Node.js setup.
For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.
Get started with 100 free API calls. No credit card required.