Upload app folder structure in one go to CouchDB database

Posted on October 20th, 2015 at 09:00 PM

CouchDB’s Futon viewer can only upload files individually so it is more than a bit tedious to load the contents of a folder. Note there is a replacement for Futon, namely Fauxton but so far we have not been able to get it to work so can’t determine if Fauxton solves the folder contents limitation.

There is a solution however in the form of Couchapp though it can be a bit of a pain to install (as is Fauxton by the way). You will need Python 2.6 or later on your local machine. We found the following installation process worked:

If not already installed, install ‘pip’:

sudo apt-get install python-pip

Then install couchapp:

sudo pip install --upgrade couchapp

If you see the following error:

http_parser/parser.c:8:22: fatal error: pyconfig.h: No such file or director #include "pyconfig.h"
you will then need to install python-dev:

sudo apt-get install python-dev
and then rerun the couchapp install

Verify couchapp is installed:

couchapp –version

Hopefully so far so good. Make sure your CouchDB service is running. Now to deploy your app you first need to create a database on the CouchDB server (you can use Futon just as easily for this). Call the database say webapp.

Now create a local folder using same name as database:

couchapp generate app webapp
this creates a typical structure under webapp:


Now copy your app files and folders into the _attachments folder say


Transfer files and folders from your local folder to the database using the following command (from the folder above webapp):

couchapp push webapp http://yourcouchdbserver:5984/webapp

All your files and folders should now be in the webapp database. Confirm with Futon though its a flat view. An alternative is to use:

curl -X GET http://yourcouchdbserver:5984/webapp/_design/webapp | python -m json.tool
with typical output:

"css/blog-home.css": "d5fd22151cd9416e79593b50a0e4538c",
"css/bootstrap.css": "c3cfe3168d972939ea258899a17140ab",
"fonts/glyphicons-halflings-regular.eot": "f4769f9bdb7466be65088239c12046d1",
"fonts/glyphicons-halflings-regular.svg": "89889688147bd7575d6327160d64e760",
"js/bootstrap.js": "6bfd171748f088ad503cb07c080b1f33",
"js/bootstrap.min.js": "046ba2b5f4cff7d2eaaa1af55caa9fd8",
"js/jquery.js": "3c9137d88a00b1ae0b41ff6a70571615",
"helloworld.html": "20d2e884d639617f6cf221382dd6b6b0"

Decide for yourself if this is ‘pretty’ json but it is a more compact view than Futon. Your app should now be ready to run. Note the _id file identifies a path prefix, in this example it should be ‘_design/webapp’.

Execute your app from the following url: http://yourcouchdbserver:5984/webapp/_design/webapp/helloworld.html

More info on using couchapp can be found here