This repository is a JavaScript and Node.js client. This package provides direct access to the Jolt protocol, offering a lightweight, dependency-free interface for building real-time distributed applications, internal services, and event-driven systems.
The Jolt JavaScript API communicates with our Jolt broker using its native TCP protocol and newline-delimited JSON messaging format. The client exposes a Node.js EventEmitter interface and supports both callback-based and Promise-based usage.
This module intentionally relies only on Node.js core libraries to ensure low overhead, portability, and minimal setup requirements. TypeScript definitions are included for typed development environments.
npm install jolt-js-apiInstallation from source:
git clone https://github.com/Jolt-Database/jolt-js-api.git
cd jolt-js-api
npm installconst JoltClient = require('jolt-js-api');
const client = new JoltClient({
host: '127.0.0.1',
port: 8080
});
client.on('connected', () => console.log('Connected to broker'));
client.on('message', (topic, data) => console.log(`[${topic}] ${data}`));
client.on('error', (error) => console.error('Error:', error));
async function main() {
await client.connect();
client.subscribe('chat.general');
client.publish('chat.general', 'Hello, Jolt!');
client.ping();
await new Promise(resolve => setTimeout(resolve, 2000));
client.close();
}
main();const client = new JoltClient(config);Configuration options:
- host: Broker hostname (default:
127.0.0.1) - port: Broker port (default:
8080)
- connect() – Establishes a connection to the broker.
- close() – Closes the client connection.
- isConnected() – Returns connection state.
- auth(username, password) – Performs broker authentication.
- subscribe(topic) – Subscribes to a topic.
- unsubscribe(topic) – Removes an existing subscription.
- publish(topic, data) – Publishes a message to a topic.
- ping() – Issues a protocol-level health check.
- connected
- ok
- error
- message
- disconnected
- socketError
- parseError
- unknown
These events provide full visibility into the broker communication, parsing results, socket behavior, and message routing.
await client.connect();
client.subscribe('chat.room1');
client.publish('chat.room1', 'Hello');['news', 'sports', 'weather']
.forEach(t => client.subscribe(t));
client.publish('news', 'Latest headline');await client.connect();
await client.subscribeAsync('chat.general');
await client.publishAsync('chat.general', 'Hello');client.on('error', (err) => {
console.error(err);
});npm test
npm run test:watch
npm run example
npm run example:advancedA running Jolt broker instance is required for full test execution.
Communication uses newline-delimited JSON over TCP.
Example request frames:
{"op": "auth", "user": "username", "pass": "password"}
{"op": "pub", "topic": "channel", "data": "message"}
{"op": "sub", "topic": "channel"}Example response frames:
{"ok": true}
{"topic": "channel", "data": "message"}