Javascript library to communicate with Centrifugo HTTP API.
$ npm i cent.js
First see available API methods in documentation.
This library contains CentClient class to send messages to Centrifugo from your node-powered backend:
import { CentClient } from 'cent.js'; // Initialize client instance. const client = new CentClient({ url: 'http://localhost:8000/api', apiKey: 'XXX' }); // Publish data into channel const publishRes = await client.publish({ channel: 'public:chat', data: {input: "test"} }).catch(err => handleError()); // We throw error in case of unsuccessful // response from Centrifugo or some other // internal errors. // Other available methods await client.unsubscribe({user: 'user_id', channel: 'channel'}); await client.disconnect({user: 'user_id'}) await client.getHistory({channel: 'channel'}) await client.getPresence({channel: 'channel'}) await client.getChannels() await client.getInfo() await client.removeHistory({channel: 'channel'})
cent.js is a native ESM package. The ESM-only package boundary is a breaking change for older Node.js releases and
CommonJS loaders. Use Node.js 20.19.x or Node.js 22.13+.
Modern CommonJS applications on those Node.js versions can synchronously load the same ESM package:
const { CentClient } = require('cent.js');
- Author - Alexey Filippov
- Twitter - @SocketSomeone