Skip to main content

Installation

npm install ensync-client-sdk

Basic Connection

const { EnSyncEngine } = require('ensync-client-sdk');

// Initialize engine (gRPC with TLS)
const engine = new EnSyncEngine("grpcs://node.gms.ensync.cloud");
// Alternative Websocket:
// const engine = new EnSyncEngine("wss://node.gms.ensync.cloud");

// Create authenticated client
const client = await engine.createClient(process.env.APP_KEY, {
  appSecretKey: process.env.APP_SECRET_KEY
});

Authentication vs Event Targeting

App Key authenticates your connection, while Client ID (appId) targets event delivery:
  • App Key: Authenticates who you are when connecting to EnSync
  • Client ID: Identifies the recipient when publishing events (this is your appId)
When you publish an event, you specify recipient Client IDs. When partners publish to you, they use your Client ID. Everyone publishes and subscribes on the same bidirectional connection.
Events are always published to specific Client IDs. Even if multiple partners subscribe to the same event type, they only receive events explicitly addressed to their Client ID.

Connection Options

const engine = new EnSyncEngine("grpcs://node.gms.ensync.cloud", {
  heartbeatInterval: 30000,
  reconnectInterval: 5000,
  maxReconnectAttempts: 5
});

Closing Connections

Always close connections when done to free resources:
// Close just this client
await client.close();

// Close client and engine (if you have no other clients)
await client.close(true);

Best Practices

  • Store credentials in environment variables, never hardcode them
  • Use secure TLS connections in production (grpcs:// or wss://)
  • Close connections when done to free resources