Skip to main content

Tutorial: Backend Quick Start

Tutorial - Learn to build a backend for your Fishjam app

This tutorial will guide you through setting up a backend server that can create rooms and manage peers for your Fishjam application.
By the end, you'll have a working backend and understand how to integrate it with your client apps.

Choose your language

Select your preferred backend language and all code examples will be shown for that language:

We'll use Node.js with TypeScript and the @fishjam-cloud/js-server-sdk package.

What you'll build

A simple backend server that can create rooms, add peers, and generate tokens for client apps.

What you'll learn

  • How to install and set up a Fishjam server SDK
  • How to create and manage rooms
  • How to create peers and generate tokens
  • How to listen for Fishjam events

Prerequisites

Step 1: Install the SDK

Install the JavaScript server SDK using your preferred package manager:

npm install @fishjam-cloud/js-server-sdk

Step 2: Get your credentials

  1. Log in to Fishjam Dashboard
  2. Navigate to your app
  3. Copy your Fishjam URL and Management Token
  4. Store them as environment variables:
export FISHJAM_URL="your-fishjam-url" export FISHJAM_MANAGEMENT_TOKEN="your-management-token"

Step 3: Set up the client

Create your Fishjam client:

import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; const fishjamUrl = process.env.FISHJAM_URL; const managementToken = process.env.FISHJAM_MANAGEMENT_TOKEN; const fishjamClient = new FishjamClient({ fishjamUrl, managementToken });

Step 4: Create a room

Create your first room:

async function createRoom() { const room = await fishjamClient.createRoom(); console.log('Room created:', room.id); return room; }

Step 5: Add a peer to the room

Create a peer and get a token for your client app:

async function addPeer(roomId: RoomId, peerName: string) { const { peer, peerToken } = await fishjamClient.createPeer(roomId, { metadata: { name: peerName }, }); console.log('Peer created:', peer.id); console.log('Peer token:', peerToken); return { peer, peerToken }; }

Step 6: Create a simple API endpoint

Build a simple HTTP endpoint that your client apps can call:

import express from 'express'; import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; const app = express(); app.use(express.json()); const fishjamClient = new FishjamClient({ fishjamUrl: process.env.FISHJAM_URL!, managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN! }); app.post('/join-room', async (req, res) => { try { const { roomName, peerName } = req.body; // Create room const room = await fishjamClient.createRoom(); // Add peer const { peer, peerToken } = await fishjamClient.createPeer(room.id, { metadata: { name: peerName }, }); res.json({ roomId: room.id, peerToken, fishjamUrl: process.env.FISHJAM_URL }); } catch (error: any) { res.status(500).json({ error: error.message }); } }); app.listen(3000, () => { console.log('Server running on port 3000'); });

Don't forget to install Express:

npm install express @types/express

Step 7: Run your server

Start your backend server:

# If using TypeScript directly npx tsx server.ts # Or compile and run npx tsc server.ts && node server.js

Step 8: Test your backend

Test your endpoint:

curl -X POST http://localhost:3000/join-room \ -H "Content-Type: application/json" \ -d '{"roomName": "test-room", "peerName": "test-user"}'

You should receive a response with:

  • roomId / room_id - The ID of the created room
  • peerToken / peer_token - Token for the client to join the room
  • fishjamUrl / fishjam_url - URL for the client to connect to

Complete example

Here's a complete working backend:

import express from 'express'; import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; const app = express(); app.use(express.json()); const fishjamClient = new FishjamClient({ fishjamUrl: process.env.FISHJAM_URL!, managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN! }); app.post('/join-room', async (req, res) => { try { const { roomName, peerName } = req.body; const room = await fishjamClient.createRoom(); const { peer, peerToken } = await fishjamClient.createPeer(room.id, { metadata: { name: peerName }, }); res.json({ roomId: room.id, peerToken, fishjamUrl: process.env.FISHJAM_URL }); } catch (error: any) { res.status(500).json({ error: error.message }); } }); app.listen(3000, () => { console.log('Fishjam backend running on port 3000'); });

Next steps

Now that you have a working backend, explore these guides:

Or learn more about Fishjam concepts: