ShareDB is a powerful realtime database backend built on Operational Transformation (OT) for JSON documents, enabling concurrent multi-user collaboration and synchronous editing with eventual consistency. It is the core realtime backend for the DerbyJS web application framework. Currently in version 5.2.2, ShareDB maintains a consistent release cadence with frequent patch and minor updates addressing bugs and performance improvements. Key features include realtime query subscriptions, easy integration with various databases (like MongoDB via `sharedb-mongo`), horizontal scalability through pub/sub, document projections, middleware support for access control, and offline change syncing. It supports both server-side and browser environments and provides access to historic document versions and realtime user presence syncing. It differentiates itself by offering a complete OT-based solution for collaborative data management.
npm install sharedbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic ShareDB server with in-memory storage and pub/sub, integrated with a WebSocket server. It initializes the backend, connects a WebSocket server, and shows how to create a document using a ShareDB connection.
Upgrade your Node.js runtime environment to version 18 or higher.
Always pass `db` and `pubsub` options to the `new Backend()` constructor, e.g., `new Backend({ db: new MemoryDB(), pubsub: new MemoryPubSub() })` or use specific implementations like `sharedb-mongo` and Redis pub/sub.Understand the 'json0' OT type for JSON operations. For custom types, extend ShareDB's type system or use `share/types` to register them correctly for your documents.
Initialize `new Backend({ db: new YourDatabaseAdapter() })`. For testing, `new MemoryDB()` can be used.Ensure that any function assigned to a middleware hook (e.g., `backend.use('connection', (request, next) => { ... })`) is indeed a function.When running ShareDB servers in Node.js, install and import a WebSocket library like `ws`: `import WebSocket from 'ws';`