Skip to main content

Node.js SDK

The Turnix Node.js SDK provides a simple and secure way to interact with the Turnix API from your backend. It helps you authenticate using your API token and easily request ICE credentials for peer-to-peer connections.

📦 Source: turnix-js on npm


📥 Installation

Install the SDK using npm:

npm install turnix-js

📦 Import the SDK

Import the TurnixIO class in your Node.js application:

import { TurnixIO } from '@turnix/js';

🔐 Authenticate with Your API Token

Create a Turnix instance using the API token you generated in the Turnix Console (see Quickstart):

const turnix = new TurnixIO({
bearerToken: 'your-bearer-token',
});
Sensitive information

Always keep your API token secret - use it only in server-side environments.


🌐 Request ICE Credentials

Use the SDK to request ICE credentials for a given client pair and room. This should be done on your backend:

const iceServers = await turnix.requestCredentials({
initiatorClient: 'alice',
receiverClient: 'bob',
room: 'room1',
ttl: 60, // optional time-to-live in seconds
});

🎯 Use ICE Servers in WebRTC

Once you have the iceServers array, pass it into your WebRTC client setup on the frontend:

const pc = new RTCPeerConnection({ iceServers });

This completes your setup for establishing a secure and reliable peer-to-peer connection using Turnix.