livedb
raw JSON → 0.5.13 verified Sat Apr 25 auth: no javascript maintenance
Database wrapper for realtime applications, providing the backend for ShareJS, Racer, and Derby. This package (v0.5.13 at current release) exposes an API for submitting operations (via OT), subscribing to document changes, and making live queries. It requires a separate database backend (e.g., livedb-mongo for MongoDB) and an optional driver for multi-server setups. Key differentiators: built for Operational Transformation, stores all operations forever, and supports live query result feeds. Note: the v5 releases listed are for the related share/sharedb package, not livedb itself; livedb appears to be in maintenance mode with no recent updates.
Common errors
error Error: Cannot find module 'livedb-mongo' ↓
cause Missing livedb-mongo package when trying to use MongoDB backend.
fix
npm install livedb-mongo
error TypeError: backend.submit is not a function ↓
cause Did not call livedb.client(db) properly; likely imported wrong symbol.
fix
Use const backend = livedb.client(db); then call backend.submit(...).
error Error: Unsupported OT type 'json0' ↓
cause OT type json0 not registered or available.
fix
Install the ot-json0 package and register it: const json0 = require('ot-json0'); livedb.types.register(json0.type);
Warnings
breaking The v5.x releases (such as v5.2.2) refer to the share/sharedb package, not livedb itself. livedb v0.5.13 is the last known version and may not receive updates. ↓
fix Consider migrating to sharedb (npm: sharedb) which is the successor.
deprecated The inprocess driver is default but deprecated for multi-server setups; it does not support cross-process operation publishing. ↓
fix Use a Redis-based driver for multi-server scenarios.
gotcha MemoryDb stores all operations in memory until server restart; data is lost on shutdown. ↓
fix Use a persistent backend like livedb-mongo for production.
gotcha Operations from different servers will not be visible unless a driver (e.g., Redis) is used; otherwise each server only sees its own operations. ↓
fix Initialize livedb with a driver: livedb.client(db, { driver: redisDriver }).
Install
npm install livedb yarn add livedb pnpm add livedb Imports
- default wrong
const livedb = require('livedb')correctimport livedb from 'livedb' - client wrong
const client = require('livedb').clientcorrectimport { client } from 'livedb' - MemoryDb wrong
import { MemoryDb } from 'livedb'correctimport { MemoryDb } from 'livedb/client'
Quickstart
const livedb = require('livedb');
const db = require('livedb-mongo')('localhost:27017/test?auto_reconnect', { safe: true });
const backend = livedb.client(db);
backend.fetchAndSubscribe('users', 'fred', function(err, data, stream) {
if (err) return console.error(err);
console.log('Initial version:', data.v);
stream.on('data', function(op) {
console.log('Operation received:', op);
});
});
backend.submit('users', 'fred', { v: 0, create: { type: 'json0', data: { name: 'Fred' } } }, function(err) {
if (err) return console.error(err);
console.log('Document created');
backend.submit('users', 'fred', { v: 1, op: [{ p: ['name', 4], si: ' Flintstone' }] }, function(err) {
if (err) return console.error(err);
console.log('Edit applied');
});
});