Why Node.js?
Node.js is the most popular runtime for TikTok LIVE integrations. The official @tiktool/live SDK is written in TypeScript, published on npm, and includes full type definitions out of the box. You get:
- Type safety - full TypeScript definitions for every event and method
- Auto-reconnection - the SDK handles dropped connections automatically
- Event-driven - familiar
.on('event', handler)pattern - Works everywhere - Node.js 18+, Bun, Deno
Install the SDK
npm install @tiktool/liveOr with other package managers:
# Yarn
yarn add @tiktool/live
# pnpm
pnpm add @tiktool/live
# Bun
bun add @tiktool/liveQuick Start: 3 Lines to Live Data
Create app.mjs and paste:
import { TikTokLive } from '@tiktool/live'
const client = new TikTokLive({
uniqueId: 'tv_asahi_news', // TikTok username (without @)
apiKey: process.env.TIKTOOL_API_KEY
})
client.on('chat', (event) => {
console.log(`${event.nickname}: ${event.comment}`)
})
await client.connect()Run it:
TIKTOOL_API_KEY=your_api_key node app.mjsYou'll see chat messages flowing in your terminal within seconds.
All Available Events
The SDK emits structured events for every interaction on the stream:
import { TikTokLive } from '@tiktool/live'
const client = new TikTokLive({
uniqueId: 'target_username',
apiKey: process.env.TIKTOOL_API_KEY
})
// Chat messages
client.on('chat', (event) => {
console.log(`[CHAT] ${event.nickname}: ${event.comment}`)
})
// Virtual gifts (Rose, Universe, etc.)
client.on('gift', (event) => {
console.log(`[GIFT] ${event.nickname} sent ${event.giftName} (${event.diamondCount} 💎)`)
})
// New followers
client.on('follow', (event) => {
console.log(`[FOLLOW] ${event.nickname} just followed!`)
})
// Likes
client.on('like', (event) => {
console.log(`[LIKE] ${event.nickname} liked (total: ${event.totalLikeCount})`)
})
// Viewer count changes
client.on('viewer_count', (event) => {
console.log(`[VIEWERS] ${event.viewerCount} watching`)
})
// Member joins (someone enters the stream)
client.on('member', (event) => {
console.log(`[JOIN] ${event.nickname} joined the stream`)
})
// Share events
client.on('share', (event) => {
console.log(`[SHARE] ${event.nickname} shared the stream`)
})
await client.connect()
console.log('✅ Connected and listening!')Expected Output
✅ Connected and listening!
[VIEWERS] 3,412 watching
[CHAT] viewer_1: Hello everyone! 👋
[FOLLOW] new_fan just followed!
[GIFT] whale_user sent Universe (34,000 💎)
[LIKE] cool_viewer liked (total: 12,847)
[CHAT] fan_123: Love this stream!
[JOIN] curious_viewer joined the stream
[SHARE] supporter_1 shared the streamTypeScript Support
The SDK is written in TypeScript. Types are included automatically - no @types package needed:
import { TikTokLive } from '@tiktool/live'
import type { ChatEvent, GiftEvent } from '@tiktool/live'
const client = new TikTokLive({
uniqueId: 'target_username',
apiKey: process.env.TIKTOOL_API_KEY
})
client.on('chat', (event: ChatEvent) => {
// event.comment, event.nickname, event.userId - all typed
console.log(event.nickname, event.comment)
})
client.on('gift', (event: GiftEvent) => {
// event.giftName, event.diamondCount, event.repeatCount - all typed
if (event.diamondCount >= 100) {
console.log(`Big gift from ${event.nickname}!`)
}
})
await client.connect()Raw WebSocket (No SDK)
Prefer to use the raw WebSocket directly? It works with any language or framework:
import WebSocket from 'ws' // npm install ws
const ws = new WebSocket(
'wss://api.tik.tools?uniqueId=tv_asahi_news&apiKey=YOUR_API_KEY'
)
ws.on('message', (raw) => {
const msg = JSON.parse(raw.toString())
switch (msg.event) {
case 'chat':
console.log(`${msg.data.user.nickname}: ${msg.data.comment}`)
break
case 'gift':
console.log(`Gift: ${msg.data.giftName} (${msg.data.diamondCount} 💎)`)
break
case 'viewer_count':
console.log(`Viewers: ${msg.data.viewerCount}`)
break
}
})
ws.on('open', () => console.log('Connected!'))FAQ
Does TikTok have an official Node.js API?
No. TikTok does not offer a public API for LIVE stream data. The TikTool Live API is a managed third-party service that provides reliable real-time access to chat, gifts, viewers, and other LIVE events. The @tiktool/live npm package is the official SDK for this API.
Is it free?
Yes. The Sandbox tier gives you 50 requests/day and 1 WebSocket connection - free forever, no credit card required. Sign up here.
Can I use it with Express, Fastify, or Next.js?
Yes. The SDK works in any Node.js environment. Use it in Express route handlers, Fastify plugins, Next.js API routes, or standalone scripts.
Does it work with Bun and Deno?
Yes. The SDK is compatible with Bun and Deno. Install via bun add @tiktool/live or import from npm in Deno.