Prerequisites

Before you can install Ditto, you must have the following:

  • Ditto access credentials

  • Node.js active long-term support (LTS) version 18.x or 20.x

  • Linux, macOS version 11 (or later), or Windows version 10 (or later)

  • Git

  • Integrated developer environment (IDE)

Installing the Demo Task App

To install Ditto in your environment, install and set up Ditto, and authenticate your client identity with the Big Peer:

1

Clone the getditto > template-app-nodejs-todo repository from GitHub:

bash
git clone https://github.com/getditto/template-app-nodejs-todo/
2

Install the required dependencies:

bash
npm install
3

Open the project in your IDE, and then open the index.ts file. For example, if using Visual Studio Code:

bash
code .
4

In line 14 of the index.ts file, replace ‘YOUR_APP_ID’ and ‘YOUR_TOKEN’ with your app ID and playground token. (See Getting SDK Connection Details)

JS
const ditto = new Ditto({
    type: "onlinePlayground",
    appID: "REPLACE_ME_WITH_YOUR_APP_ID",
    token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
    customAuthURL: "REPLACE_ME_WITH_YOUR_AUTH_URL",
    enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs
})

const config = new TransportConfig()
config.connect.websocketURLs.push('wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL')

ditto.setTransportConfig(config)
ditto.startSync()
5

Build the demo task app:

bash
npm run build
6

Interact with the demo task app and simulate real-time peer-to-peer replication by running the demo task app in two or more separate terminals (one for each small peer):

bash
node index.js
7

Using the commands that automatically appear in each of your terminals, add, remove, and modify documents as desired.

8

If you want to observe your changes sync with the cloud-optional deployment, the Big Peer, open the data browser in the Ditto portal.