Building a CouchApp using Node.js on Windows

In this post, I’d like to help out Windows users who wish to create a Node.js application on a windows box and are interested in a easy alternative to traditional web server hosting. 

I love relational database applications, and have been writing them for (literally) decades now.  Recently I’ve been trying to explore what NoSql has to offer, and I discovered an interesting use of NoSql, that is, hosting. 

CouchDB offers a capability called CouchApp which allows your Couch to host data and act as a web server simultaneously.  Evidently, this does scale surprisingly well, and because of CouchDB’s built in replication capabilities, it offers a pretty flexible solution in a dead simple package.

Quite a few of the people who pioneer and describe this tech are UNIX/Mac users.  I don’t have a UNIX or Mac development machine set up right now, so I thought I’d give it a try on Windows.

Most of the information in this post was adapted from Max Ogden’s video post.

You’ll need the following installs:

You can use NPM to install CouchApp

Create a directory for your application.  I’ve put mine in C:\Temp\MomsTattoos.

If you’ve installed Node.Js in the normal place, you should be able to open up a command prompt in your new directory and type something like this, to get CouchApp installed:

%PROGRAMFILES%\nodejs\npm install couchapp

My Node JS is in the system path, so this is what I did:


Take a look around

You can see your new couch app options by typing: node_modules\.bin\couchapp


The boiler option creates a generic version of a CouchApp, but there may be a small problem when you try it.


This can be fixed by opening the main.js file in node_modules\.bin\couchapp

and editing line 2 from

, sys = require(‘sys’)


, sys = require(‘util’)


If you attempt the boiler command again you will get:


This is because the command actually did generate the app the first time it was used (despite the error).  Your project should now look something like this:


Now you can open up the starting point of your application, App.js.  This file contains code similar to the routing constructs in MS MVC (if you are familiar with that).  Go ahead and change the _id property in the ddoc variable to match your application.  Here’s what mine looks like:

var couchapp = require('couchapp')

  , path = require('path')



ddoc =

  { _id:'_design/MomsTattoos'

  , rewrites :

    [ {from:"/", to:'index.html'}

    , {from:"/api", to:'../../'}

    , {from:"/api/*", to:'../../*'}

    , {from:"/*", to:'*'}





ddoc.views = {};


ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {

  if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {

    throw "Only admin can delete documents on this database.";




couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));


module.exports = ddoc;

view rawapp.js

Open up Index.html and alter it slightly to show some content in the body.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">



    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="keywords" content="" />

    <meta name="description" content="" />


    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />

    <link rel="shortcut icon" type="image/png" href="favicon.png" />



    <link href="layout.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript" src="jquery-1.4.4.min.js"></script>

    <script language="javascript" type="text/javascript" src="sammy/sammy.js"></script>

    <script language="javascript" type="text/javascript" src="site.js"></script>




    <h1>Hello World</h1>



view rawIndex.html

You will need a database in the couch to store the application.  Open a browser and go to

Create a database and name it momstattoos (or whatever your app is called).


Now save yourself some hassle by copying the app files (app.js and attachments folder) one level down (to the first MomsTattoos directory) and delete the inner MomsTattoos directory.

Now your directory tree should look more like this:


Deploy your application

From the MomsTattoos directory, use this command: node_modules\.bin\couchapp push %CD%\app.js http://localhost:5984/momstattoos


Now you’re hosting your first CouchApp. To check it out go to

In Summary

In this post, I pulled together the basics for building a hello world CouchApp on a Windows box.  In my next post, I’ll try to get a more complete application running with the goal of accessing NoSql data from a more complex client application.

One thought on “Building a CouchApp using Node.js on Windows”

Comments are closed.