This demonstrates a small Node.js CLI client opening a database, connecting PowerSync and running live queries.
This demo is configured to talk to an example backend you can host yourself. To get started:
- Start one of the Node.js backend examples from the self-host-demo repository.
- If necessary, change
.envto point to the started backend and sync service. cdinto this directory and runpnpm install.- Run
pnpm start.
This opens the local database, connects to PowerSync, waits for a first sync and then runs a simple query. Results from the query are printed every time it changes. Try:
- Updating a row in the backend database and see changes reflected in the running client.
- Enter
add('my list')and see the new list show up in the backend database.
The demo also starts PowerSync DevTools and prints its link. Open the link to see the sync status, buckets, local data and logs of this client.
This demo can use encrypted databases with the better-sqlite3-multiple-ciphers package.
To test encryption, set the ENCRYPTION_KEY in .env to a non-empty value.
For more details, see the documentation for the PowerSync node package and check other examples:
- example-electron-node: An Electron example that runs PowerSync in the main process using the Node.js SDK.