SDK setup
Use these instructions to setup an Ably SDK. About Pub/Sub outlines the differences between the realtime and REST interfaces in Ably SDKs and the other possible ways to use Ably.
Get an API key
An API key is required to instantiate a client and authenticate with Ably. API keys are used either to authenticate directly, or to generate Tokens for untrusted clients. Sign up to Ably to create an API key in the dashboard or use the Control API to create an API programmatically.
Ably SDKs provide a consistent and idiomatic API across a variety of supported platforms. They contain a realtime and a REST interface, each of which can be used to satisfy different use cases. Choose which SDK you’d like to start using by selecting the language from the dropdown menu above.
The NodeJS SDK is available as an NPM module. To get started with your project, install the package.
npm install ably
CopyCopied!
Run the following to instantiate a client:
const Ably = require('ably');
const realtime = new Ably.Realtime({ key: apiKey });
CopyCopied!
Client options
ClientOptions
enable the client connection to be configured when instantiating the client.
Properties that can be set include those used to:
- authenticate the client, such as
key
if using basic authentication, or anauthUrl
orauthCallback
if using token authentication. - customize client behavior, such as using
echoMessages
to set whether messages published by the client are received by them, oridempotentRestPublishing
to enable idempotent publishing. - set retry and timeout durations.
- set environment names and fallbacks if using a custom environment.
See the API references for a full list of properties available to the realtime and REST interfaces.