The first post was about dnode - the freestyle rpc library for node, the second was about optimist - the lightweight options parser for node, the third was about lazy - lazy lists for node, the fourth was about request - the swiss army knife of HTTP streaming, the fifth was about hashish - hash combinators library, the sixth was about read - easy reading from stdin, the seventh was about ntwitter - twitter api for node, the eighth was about socket.io that makes websockets and realtime possible in all browsers, the ninth was about redis - the best redis client API library for node, the tenth was on express - an insanely small and fast web framework for node, the eleventh was semver - a node module that takes care of versioning.

Today I'll introduce you to cradle - a high-level, caching, CouchDB client for Node.js. Cradle is written by Alexis Sellier (cloudhead).

Cradle is somewhat higher-level than most other CouchDB clients, requiring a little less knowledge of CouchDB's REST API. Cradle also has built-in write-through caching, giving you an extra level of speed, and making document updates and deletion easier. Cradle was built from the love of CouchDB and Node.js, and tries to make the most out of this wonderful marriage of technologies.

Cradle supports all the operations that you'd expect an API for CouchDB to support like creating a database:

vardb=c.database('starwars');db.create();

Checking if a db exists:

db.exists(function(err,exists){if(err){console.log('error',err);}elseif(exists){console.log('the force is with you.');}else{console.log('database does not exists.');db.create();/* populate design documents */}});

Destroying a db:

db.destroy(cb);

Fetching a document:

db.get('vader',function(err,doc){console.log(doc);});

Querying a view:

db.view('characters/all',function(err,res){res.forEach(function(row){console.log(row.name+" is on the "+row.force+" side of the force.");});});

Sponsor this blog series!

Doing a node.js company and want your ad to appear in the series? The ad will go out to 14,000 rss subscribers, 7,000 email subscribers, and it will get viewed by thousands of my blog visitors! Email me and we'll set it up!