Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with CouchDB


CouchDB is an open source Apache project and, like MongoDB, is a no-SQL, document database.

In this section, we will see how to use CoffeeScript to perform create, read, update, and delete actions with a CouchDB database.

You can find more information on CouchDB, including information on downloading, installing, and using CouchDB from the project's home page located at http://couchdb.apache.org/.

Opening a connection

We will use the cradle NPM package to connect to our CouchDB server. In this example, we will open a connection and verify the existence of a database and, if it does not exist, we will create it.

Getting ready...

Once CouchDB has been installed, install cradle with the following command:

npm install cradle --save

How to do it...

  1. Require cradle and create a connection to a database named test:

    cradle = require 'cradle'
    db = (new(cradle.Connection)).database 'test'
  2. Use the exists() function to see whether the test database exists:

    db.exists (err, exists) ->
  3. If it...