Overview
PulseGrid lets your backend manage realtime infrastructure safely while your clients connect with short-lived client tokens.
Recommended JavaScript flow:
1. Create a PulseGrid client
2. Test authentication
3. Create a client token
4. Connect to a channel
5. Send live websocket messages
6. Publish server-side events when needed
Setup
1. Install the PulseGrid npm package in your Node.js project.
2. Store your PulseGrid base URL, public key, secret key, and project ID in environment variables.
3. Create a client with createPulseGrid(...).
4. Use token creation on the backend and use the returned token for realtime clients.
Code example
import { createPulseGrid } from "pulsegrid";
const pulsegrid = createPulseGrid({
baseUrl: process.env.PULSEGRID_BASE_URL,
publicKey: process.env.PULSEGRID_PUBLIC_KEY,
secretKey: process.env.PULSEGRID_SECRET_KEY,
projectId: process.env.PULSEGRID_PROJECT_ID,
});
const token = await pulsegrid.tokens.create({
identifierId: "user_123",
identifierLabel: "Kwandile",
allowedChannels: ["demo-channel"],
expiresIn: 3600,
});
const chat = await pulsegrid.channel("demo-channel").connect({
clientToken: token,
onOpen: () => console.log("Connected"),
onMessage: (payload) => console.log(payload),
});
chat.send("Hello from PulseGrid");
Notes
Keep the secret key on the backend only.
Do not expose the secret key in browser or mobile client code.
Frontend and mobile apps should use short-lived client tokens instead.