node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป


Backbone Cradle

Extension for Backbone to use Cradle as an interface to a CouchDB database for Model persistence. Intended for server-side use of Backbone, but should work if accessing the database directly.

View creation is not supported as cradle already handles this very gracefully.

This library was originally based on Development Seeds' backbone-couch, but in the end takes quite a different approach.

To ensure compatibility with Ruby's CouchRest Model (also maintained by Sam Lown), ensure the 'type' column, is always set in your models.


  • 2011-10-31 - 0.1.1
  • Upgraded to Cradle 0.5.7


npm install backbone-cradle


// Prepare Backbone and Cradle along with a default database
// called 'documents'
var Backbone = require('backbone'),
    cradle   = require('cradle'),
    db       = new (cradle.Connection)().database('documents')

// Create a new backbone-cradle handler
var Couch = require('backbone-cradle')(cradle, db);

// Create your backbone Models using the new handler
var Document = Couch.Model.extend({
  initialize: function() {
    // always set the type for CouchRest Compatibility
    this.set({type: 'Document'});

// Do the same for your collections
var DocumentList = Couch.Collection.extend({
  // Name of view to use is always required!
  viewName: 'Document/all'

Run tests

Requires Expresso. Tested with version 0.7.6.

cd backbone-cradle/
npm test


Add support for dynamic collections with a similar implementation to Jan Monschke's backbone-couchdb library.