SDK Setup Guides
JavaScript
Installing JavaScript SDK
you can integrate the ditto sdk with your web and node js projects developed using javascript and https //www typescriptlang org/ languages for a complete overview of the platforms, transports, and devices that the javascript sdk supports, see docid\ n 0eyf9ppw3vqund4 ryt if you're using node js and want instructions on how to create a task app, see the docid\ dj9ujvyyxqtelm94i1mzi and the docid\ eskclleqpjnfkqshxvtiq 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 and starting sync ) authenticate with the big peer and then start syncing offline ( /#running ditto ) prerequisites following are the minimum requirements that must be met before attempting to install ditto https //nodejs org/en/ long term support (lts) version 14 0 linux, macos version 11, or windows version 10 0 installing dependencies install the @dittolive/ditto package into your project npm npm install @dittolive/ditto integrating ditto and starting sync 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 docid\ jqjyl9gbvsgi9vlw3ywvc for an introduction to authentication in ditto, see ditto basics > docid\ c802c1qiakfga2qxmcywu import { init, ditto } from "@dittolive/ditto"; let ditto; async function main() { await init() ditto = new ditto({ type "onlineplayground", appid "your app id", token "your playground token" }) ditto startsync() } main() running ditto if you're using typescript, you must create the javascript file by running the following command bash tsc then, you can execute the file bash node index js setting up subscriptions you must create a subscription object in the global scope so that ditto synchronizes in the background throughout the duration of the program import { init, ditto } from '@dittolive/ditto' let ditto let subscription let livequery async function main () { await init() ditto = new ditto({ type 'onlineplayground', appid 'your app id', token 'your token here'}) ditto startsync() // start a subscription subscription = ditto store collection("tasks") find("isdeleted == false") subscribe() } main() listening to changes 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 docid\ eskclleqpjnfkqshxvtiq tutorial import { init, ditto } from '@dittolive/ditto' let ditto let subscription let livequery async function main () { await init() ditto = new ditto({ type 'onlineplayground', appid 'your app id', token 'your token here'}) ditto startsync() subscription = ditto store collection("tasks") find("isdeleted == false") subscribe() // listen for changes livequery = ditto store collection("tasks") find("isdeleted == false") observelocal((docs, event) => { console log(docs) }) ditto store collection("tasks") upsert({ iscompleted false, isdeleted false, body "hello world!" }) } main()