If you are a creator or marketer, "trend research" usually means scrolling TikTok for 3 hours and calling it work.
But what if you could just run a script and get a list of:
- The top trending hashtags right now.
- The most popular music/sounds being used.
- The breakout creators of the day.
In this tutorial, weโll build a TikTok Trend Tracker using Node.js and the SociaVault API.
The Goal
We want a command-line tool that outputs a daily report like this:
๐ฅ TOP TRENDING HASHTAGS
1. #fyp (2.1B views)
2. #coding (500M views)
3. #ai (300M views)
๐ต VIRAL MUSIC
1. "Original Sound - User123"
2. "Flowers - Miley Cyrus"
Prerequisites
- Node.js installed.
- A SociaVault API Key.
Step 1: Project Setup
mkdir tiktok-trends
cd tiktok-trends
npm init -y
npm install axios dotenv
Create .env:
SOCIAVAULT_API_KEY=your_api_key
Step 2: Fetching Trends
We'll use two powerful endpoints:
-
/v1/scrape/tiktok/trending: Gets the current trending feed. -
/v1/scrape/tiktok/music/popular: Gets the top sounds.
Create tracker.js:
require('dotenv').config();
const axios = require('axios');
const API_KEY = process.env.SOCIAVAULT_API_KEY;
const BASE_URL = 'https://api.sociavault.com/v1/scrape/tiktok';
const headers = {
'Authorization': `Bearer ${API_KEY}`
};
async function getTrendingFeed() {
try {
console.log('๐ Fetching trending feed...');
const response = await axios.get(`${BASE_URL}/trending`, { headers });
return response.data.data || [];
} catch (error) {
console.error('Error fetching feed:', error.message);
return [];
}
}
async function getPopularMusic() {
try {
console.log('๐ต Fetching popular music...');
const response = await axios.get(`${BASE_URL}/music/popular`, { headers });
return response.data.data || [];
} catch (error) {
console.error('Error fetching music:', error.message);
return [];
}
}
Step 3: Analyzing the Data
The raw data is huge. We need to extract the insights.
function analyzeTrends(videos) {
const hashtags = {};
videos.forEach(video => {
// Extract hashtags from description
const tags = video.desc.match(/#[\w]+/g) || [];
tags.forEach(tag => {
hashtags[tag] = (hashtags[tag] || 0) + 1;
});
});
// Sort by frequency
return Object.entries(hashtags)
.sort((a, b) => b[1] - a[1])
.slice(0, 10); // Top 10
}
Step 4: The Main Loop
Now let's put it all together.
async function main() {
console.log('๐ Starting Trend Tracker...\n');
// 1. Get Data
const [videos, music] = await Promise.all([
getTrendingFeed(),
getPopularMusic()
]);
// 2. Analyze Hashtags
const topTags = analyzeTrends(videos);
// 3. Print Report
console.log('\n๐ฅ TOP TRENDING HASHTAGS (from current feed)');
console.log('-------------------------------------------');
topTags.forEach((tag, i) => {
console.log(`${i + 1}. ${tag[0]} (Found in ${tag[1]} videos)`);
});
console.log('\n๐ต VIRAL MUSIC');
console.log('-------------------------------------------');
music.slice(0, 5).forEach((song, i) => {
console.log(`${i + 1}. ${song.title} - ${song.author}`);
});
}
main();
Why Use an API?
TikTok's web structure is notoriously difficult to scrape. It uses:
- Dynamic class names (obfuscation).
- Infinite scrolling.
- Heavy fingerprinting.
If you try to scrape this with Selenium or Puppeteer, you will spend 90% of your time fixing broken selectors. Using an API like SociaVault lets you focus on the data, not the scraping infrastructure.
Taking It Further
You could expand this script to:
- Save to Database: Store daily trends in Postgres/Supabase to track longevity.
- Alerts: Send a Discord notification when a specific keyword (e.g., "crypto") enters the top 10.
- Content Gen: Use OpenAI to generate video ideas based on the trending hashtags.
Happy coding!
Top comments (0)