# 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](https://www.npmjs.com/package/turnix-js)

---

### 📥 Installation

Install the SDK using npm:

```bash
npm install turnix-js
```

---

### 📦 Import the SDK

Import the TurnixIO class in your Node.js application:

```javascript
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](https://turnix.io/docs/getting-started/quickstart)):

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

> **Warning: 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:

```javascript
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:

```javascript
const pc = new RTCPeerConnection({ iceServers });
```

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