Getting Started

Get up and running with NoLag in under 5 minutes.

Prerequisites

  • A NoLag account (sign up free)
  • Node.js 18+ (for JavaScript SDK)
  • A project and app created in the NoLag dashboard

Step 1: Install the SDK

Install the NoLag SDK for your preferred language:

npm install @nolag/js-sdk

Step 2: Get Your Access Token

  1. Log in to the NoLag Dashboard
  2. Navigate to your project
  3. Go to API Keys section
  4. Create a new API key or copy an existing one

Step 3: Connect to NoLag

import { NoLag } from '@nolag/js-sdk'

// Create client and connect
const client = NoLag('your_access_token')
await client.connect()

console.log('Connected to NoLag!')

Step 4: Subscribe to a Topic

Topics are channels for messages. Subscribe to receive messages published to a topic:

// Set up app and room, then subscribe
const room = client.setApp('my-app').setRoom('general')
room.subscribe('messages')

// Listen for messages
room.on('messages', (data) => {
  console.log('Received:', data)
})

Step 5: Publish a Message

Publish messages to a topic for all subscribers to receive:

// Publish a message
room.emit('messages', {
  text: 'Hello, World!',
  sender: 'user-123',
  timestamp: Date.now()
})

Complete Example

Here's a complete example in your preferred language:

import { NoLag } from '@nolag/js-sdk'

// Connect to NoLag
const client = NoLag('your_access_token')
await client.connect()

// Set up app and room
const room = client.setApp('my-app').setRoom('general')

// Subscribe to a topic
room.subscribe('messages')

// Listen for messages
room.on('messages', (data) => {
  console.log('Received:', data)
})

// Publish a message
room.emit('messages', { text: 'Hello, World!' })

Next Steps