Skip to content
Collaborative editing in any app
JavaScript CoffeeScript
Find file
Pull request Compare This branch is 1 commit ahead, 1115 commits behind share:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a little server (& client library) to allow concurrent editing of any kind of content. The server runs on NodeJS and the client works in NodeJS or a web browser.

ShareJS supports operational transform on plain-text and arbitrary JSON data. Rich text support is planned.

Check out some cool demos.

Installing and running

npm install share

Note: Until I update sharejs in npm, you'll need this too: cd node_modules/share cake build

Run the examples with:

# sharejs-exampleserver

From source

Install some dependancies


# sudo brew install redis


# sudo apt-get install redis


# npm install -g connect coffee-script redis nodeunit
# git clone git://
# cd ShareJS

Run the tests:

# cake test

Build the coffeescript into .js:

# cake build
# cake webclient

Run the example server:

# bin/exampleserver

Running a server

There are two ways to run a sharejs server:

  1. Embedded in a node.js server app:

    var connect = require('connect'),
        sharejs = require('share').server;
    var server = connect(
          connect.static(__dirname + '/my_html_files')
    var options = {db: {type: 'memory'}}; // See docs for options. {type: 'redis'} to enable persistance.
    // Attach the sharejs REST and interfaces to the server
    sharejs.attach(server, options);
    console.log('Server running at');

    The above script will start up a ShareJS server on port 8000 which hosts static content from the my_html_files directory. See bin/exampleserver for a more complex configuration example.

See the Connect or Express documentation for more complex routing.

  1. From the command line:

    # sharejs

    Configuration is pulled from a configuration file that can't be easily edited at the moment. For now, I recommend method #1 above.

  2. If you are just mucking around, run:

    # sharejs-exampleserver

    This will run a simple server on port 8000, and host all the example code there. Run it and check out http://localhost:8000/ . The example server stores everything in ram, so don't get too attached to your data.

If you're running sharejs from source, you can launch the example server by running bin/exampleserver.

Putting Share.js on your website

If you want to get a simple editor working in your webpage with sharejs, here's what you need to do:

First, get an ace editor on your page:

<div id="editor"></div>

Your web app will need access to the following JS files:

Add these script tags:

<script src=""></script>
<script src="/"></script>
<script src="/share/share.js"></script>
<script src="/share/share-ace.js"></script>

And add this code:

    var editor = ace.edit("editor");'hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {

Thats about it :)

The easiest way to get your code running is to check sharejs out from source and put your html and css files in the examples/ directory. Run bin/exampleserver to launch the demo server and browse to http://localhost:8000/your-app.html .

See the wiki for documentation.

Writing a client using node.js

The client API is the same whether you're using the web or nodejs.

Here's an example application which opens a document and inserts some text in it. Every time an op is applied to the document, it'll print out the document's version.

Run this from a couple terminal windows when sharejs is running to see it go.

var client = require('share').client;

// Open the 'hello' document, which should have type 'text':'hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {
    // Insert some text at the start of the document (position 0):
    doc.submitOp({i:"Hi there!\n", p:0});

    // Get the contents of the document for some reason:

    doc.on('change', function(op) {
        console.log('Version: ' + doc.version);

    // Close the doc if you want your node app to exit cleanly
    // doc.close();

See the wiki for API documentation, and examples/node* for some more example apps.

Something went wrong with that request. Please try again.