ShareJS - Concurrent Document Editing

0.7.40 · abandoned · verified Wed Apr 22

ShareJS is a server and client library designed for real-time, concurrent document editing using operational transformation (OT). It supports OT on plain-text and arbitrary JSON data, allowing multiple users to collaborate on content simultaneously. The server component runs on Node.js, while the client library functions in both Node.js and web browsers, aiming for broad browser compatibility. It depends on LiveDB for its database backend and data model, and explicitly requires developers to provide a communication transport layer that guarantees in-order message delivery, warning against common pitfalls like using Socket.IO without careful configuration. The current stable version mentioned is 0.7.40. Key differentiators include its transport-agnostic design and its focus on raw OT primitives, leaving UI implementation to the developer. The project appears to be unmaintained as of early 2026, with no recent activity on its GitHub repository since around 2017.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a ShareJS server with an in-memory LiveDB backend and sets up a WebSocket server to handle client connections, demonstrating the basic server-side setup.

const livedb = require('livedb');
const share = require('share');
const http = require('http');
const express = require('express');
const WebSocket = require('ws');

// 1. Initialize LiveDB backend (in-memory for simple example)
const backend = livedb.client(livedb.memory());

// 2. Create ShareJS server instance
const shareServer = share.server.createClient({backend: backend});

// 3. Set up HTTP server for serving client-side code (optional, but common)
const app = express();
app.use(express.static(__dirname + '/public')); // Serve static files

const httpServer = http.createServer(app);
const wss = new WebSocket.Server({ server: httpServer });

// 4. Handle WebSocket connections for ShareJS clients
wss.on('connection', (ws) => {
  const stream = WebSocket.createWebSocketStream(ws);
  shareServer.listen(stream);
  console.log('New ShareJS client connected via WebSocket.');
});

const PORT = process.env.PORT || 8000;
httpServer.listen(PORT, () => {
  console.log(`ShareJS server listening on http://localhost:${PORT}`);
  console.log('You will need a client-side implementation to connect.');
});

view raw JSON →