There are many, many libraries available for working with CouchDB from NodeJS. My particular favourite is an excellent little library, aptly named nano. Despite having some great success with nano over the last few months, I’ve been thinking more and more about the fact that sooner or later I’m going to want to being using the same library from the browser as I do in Node.
A little while ago, I probably would have just put this in the too hard basket, but thanks to some excellent work from TJ Holowaychuk we have a little XHR library available called SuperAgent. While it’s still early days for SuperAgent, it does a bang up job of offering both an in-browser replacement to jQuery’s $.ajax function and also various http client libraries in Node (with request being my personal favourite).
With SuperAgent available, it opens up a couple of possibilities for getting a CouchDB client library that works in both the browser and in Node:
- Fork nano, and replace request with SuperAgent
- Build a new experimental CouchDB library
Being a sucker for experiments, rightly or wrongly, I went for option 2. And lo, SuperComfy (early docs here) was born.
It is similar in feel to nano, with a few exceptions and additional features:
- REST methods are as purely mapped as possible. SuperAgent does a good job of this, and SuperComfy doesn’t break that good work. For the most part, this is something nano does as well, with the exception of things like
insertinstead ofput. - Based on the requirements of Steelmesh 2.0, SuperComfy has some pretty nifty functionality that allows you to redirect writes to another database. Very useful in cases where you have a replicated environment and would like to avoid replication conflicts…
If you are feeling a little wild, feel free to take SuperComfy for a spin, and let us know your thoughts.
