Installing JavaScript SDK
You can integrate the Ditto SDK with your web and Node.js projects developed using JavaScript and TypeScript languages.
For a complete overview of the platforms, transports, and devices that the JavaScript SDK supports, see Compatibility with JavaScript.
If you're using Node.js and want instructions on how to create a task app, see the Node.js Task App Quickstart and the Task App: Node.js tutorial.
To install the JavaScript SDK:
Confirm that you meet the minimum requirements. (Prerequisites)
Install the ditto package in your environment. (Installing Dependencies)
Import and initialize Ditto in your app. (Integrating Ditto)
Authenticate with the Big Peer and then start syncing offline. (Integrating and Initializing)
Following are the minimum requirements that must be met before attempting to install Ditto.
- Linux, macOS version 11, or Windows version 10.0
Install the @dittolive/ditto package into your project:
Import and initialize Ditto, and then provide your access credentials for one-time authentication with the Big Peer:
- From the top-most scope of your app, import Ditto.
- Using async await, initialize Ditto.
- Provide your access credentials:
- Replace the appID placeholder value with the app ID that identifies your app in Ditto.
- Replace the token placeholder value with your playground token that the Big Peer uses to verify your digital identity before issuing your playground certificate.
Make sure to instantiate the ditto object in the top-most scope of your app. Otherwise, it may be inadvertently garbage collected and no longer accessible throughout the lifecycle of your app.
For instructions on how to obtain your access credentials, see Onboarding. For an introduction to authentication in Ditto, see Ditto Basics > Authentication and Initialization.
If you're using typescript, you must create the JavaScript file by running the following command:
Then, you can execute the file:
You must create a subscription object in the global scope so that ditto synchronizes in the background throughout the duration of the program.
Using the observeLocal method, as follows, for every change to a document, you can retrieve those documents and print them to the console:
For a step-by-step demonstration of how to create a basic task app, see the Task App: Node.js tutorial.