Skip to content
CouchDB in the browser
JavaScript
Pull request Compare This branch is 4 commits ahead of peterbraden:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
html
lib
.hgtags
README.textile
app.js
browser-couch.js
deploy
server.js

README.textile

About

This is experimental proxy server in node.js. It does two basic things:

  • serves as a proxy between browser and your web server as well as CouchDB,
  • WebSockets for fast master-slave replication with CouchDB.

Why?

  • Browsers, for security reasons, don’t allow cross-domain ajax request, required for full CouchDB support = need for web and couch server to be available on the same port,
  • WebWorkers are good for reducing load and optimizing speed especially for extensive master-to-many-slaves replications.

Demo

Fire up your CouchDB server:

$ couchdb
Apache CouchDB 1.0.0 (LogLevel=info) is starting.
Apache CouchDB has started. Time to relax.
[info] [<0.33.0>] Apache CouchDB has started on http://127.0.0.1:5984/

Fire up your web server:

$ cd ./html/
$ thin -A file start
>> Using file adapter
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

Fire up our proxy server (it may require root):

$ node server.js
25 Jul 21:03:34 - socket.io ready - accepting connections

Open browser (which supports WebSockets like newest Chrome or Firefox) and go to: http://127.0.0.1:8080/console.html.
This is console. You can do basic CRUD request to your DB. For example select PUT and enter: /. It will create new database “browsercouch” (which is default name. You can change it in ./server.js file).

Refresh page, open another browser window and go to the same console page. Then choose POST and type / {"hello": "world"}. This will save new document in database. Notice how fast this update appeared in the other browser window.

Future

  • Replace BrowserCouch’s ajax replications with WebSockets,
  • pass specs,
  • make similar console for communication with BrowserCouch.
Something went wrong with that request. Please try again.