SDK 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\ yvt2seslu1zlcx3w c9bq if you're using node js and want instructions on how to create a task app, see the docid\ p4t3w99a 1tn0hqeh3o0y and the docid\ lcmnjvxz5tf 0ygh55hfu 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/ active and maintenance long term support (lts) linux, macos version 11, or windows version 10 0 installing dependencies install the @dittolive/ditto package into your project bash 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\ hk2s3ld8sj ti5snxwkq1 for an introduction to authentication in ditto, see ditto basics > docid\ tu7x wqhliyzemgkos0wv 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 add a sync subscriptions use the ditto sync namespace to add a sync subscription import { init, ditto } from '@dittolive/ditto' let ditto async function main () { await init() ditto = new ditto({ type 'onlineplayground', appid 'your app id', token 'your token here'}) ditto startsync() // add a sync subscription ditto sync registersubscription(` select from tasks where isdeleted = false`) } 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\ lcmnjvxz5tf 0ygh55hfu tutorial import { init, ditto } from '@dittolive/ditto' let ditto async function main () { await init() ditto = new ditto({ type 'onlineplayground', appid 'your app id', token 'your token here'}) ditto startsync() // add a sync subscription ditto sync registersubscription(` select from tasks where isdeleted = false`) // add a store observer ditto store registerobserver(` select from tasks where isdeleted = false`, {} / empty args /, (result) => { console log(result items) }) const newtask = { iscompleted false, isdeleted false, body "hello world!" } // inserting a new document ditto store execute(` insert into tasks documents (\ newtask)`, { newtask }) } main()