-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (24 loc) · 1003 Bytes
/
app.js
File metadata and controls
33 lines (24 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var connect = require('connect'),
sharejs = require('ShareJS').server;
var server = connect(
connect.logger(),
connect.static(__dirname + '/html')
);
var options = {db: {type: 'memory'}}; // See docs for options. {type: 'redis'} to enable persistance.
// Attach the sharejs REST and Socket.io interfaces to the server
sharejs.attach(server, options);
server.listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
var client = require('ShareJS').client;
// Open the 'hello' document, which should have type 'text':
client.open('hello', 'text', 'http://localhost:8000/sjs', function(error, doc) {
// Insert some text at the start of the document (position 0):
doc.insert("Hi there!\n", 0);
// Get the contents of the document for some reason:
console.log(doc.snapshot);
doc.on('change', function(op) {
console.log('Version: ' + doc.version);
});
// Close the doc if you want your node app to exit cleanly
// doc.close();
});