DEV Community

Cover image for Build a TikTok Trend Tracker with Node.js (No Login Required)
Olamide Olaniyan
Olamide Olaniyan

Posted on

Build a TikTok Trend Tracker with Node.js (No Login Required)

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:

  1. The top trending hashtags right now.
  2. The most popular music/sounds being used.
  3. 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"
Enter fullscreen mode Exit fullscreen mode

Prerequisites

Step 1: Project Setup

mkdir tiktok-trends
cd tiktok-trends
npm init -y
npm install axios dotenv
Enter fullscreen mode Exit fullscreen mode

Create .env:

SOCIAVAULT_API_KEY=your_api_key
Enter fullscreen mode Exit fullscreen mode

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 [];
  }
}
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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();
Enter fullscreen mode Exit fullscreen mode

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:

  1. Save to Database: Store daily trends in Postgres/Supabase to track longevity.
  2. Alerts: Send a Discord notification when a specific keyword (e.g., "crypto") enters the top 10.
  3. Content Gen: Use OpenAI to generate video ideas based on the trending hashtags.

Happy coding!

Top comments (0)