Following are the minimum requirements that must be met before attempting to install Ditto.
- Node.js long-term support (LTS) version 14.0
- 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.
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: