Accessing CouchDB changes stream with Cradle

One of CouchDB's most noteworthy features is the _changes API. With it we can view all alterations to a database via HTTP.

For instance, to see all changes made to our quotes database we can make a GET request to http://localhost:5984/quotes/_changes. Even better, if we wanted to hook up to a live stream, we would add the query parameter ?feed=continuous.

Cradle provides an attractive interface to the _changes API, which we'll explore in this recipe.

Getting ready

We'll need a functioning CouchDB database and a way to write to it. We can use the quotes.js example used in Storing data to CouchDB with Cradle, so let's copy that into a new directory and then create a file alongside it called quotes_stream.js ...

Get Node Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.