Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including couchshell with all npm packages installed. Try it out:

couchshell lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("couchshell/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

couchshell v1.2.0

A shell to interact with CouchDB as if it were a file system


   _____                 _      _____ _          _ _ 
  / ____|               | |    / ____| |        | | |
 | |     ___  _   _  ___| |__ | (___ | |__   ___| | |
 | |    / _ \| | | |/ __| '_ \ \___ \| '_ \ / _ \ | |
 | |___| (_) | |_| | (__| | | |____) | | | |  __/ | |
  \_____\___/ \__,_|\___|_| |_|_____/|_| |_|\___|_|_|

Couchshell is a command-line shell utility that allows you to interact with a CouchDB/Cloudant interface as if it were a Unix file system.

  • mkdir - create database
  • rmdir - remove database
  • cd - change database
  • ls/ll - list contents of database or list of databases
  • cat - show contents of document or datbase stats
  • echo - create document
  • rm - remove document
  • cp - copy a document or database
  • head - show first few documents from a database
  • touch - load and save a document
  • pwd - show the current database
  • tree - show revision history and conflicts from a document
  • du - show disk space usage of a database
  • fsck - remove conflicts from a document


npm install -g couchshell

Define the URL of your CouchDB/Cloudant server

Set an environment variable called COUCH_URL which contains the URL of your CouchDB or Cloudant instance e.g.

export COUCH_URL=


export COUCH_URL=

IAM Authentication

Alternatively, if you are using IAM authentication with IBM Cloudant, then supply two environment variables:

  • COUCH_URL - the URL of your Cloudant host e.g. (note absence of username and password in URL).
  • IAM_API_KEY - the IAM API KEY e.g. ABC123515-151215.

Starting couchshell

$ couchshell
Type "help" or press enter for a list of commands

You now have access to your CouchDB server as if is a file system with databases represented as directories at the root level and documents as files inside the directories.

Create database (directory)

>> mkdir mydb

Change directory

We can deal with a database by using the cd shell commmand:

>> cd mydb
mydb >>

Or return back to the home directory with

>> cd ..

View the contents of a directory

We can see the contents of a directory with ls:

>> ls
_replicator _users accidents anagrammer articles cache conference db10 feeds geoquiz geoquiz_stats houseprices

or ll:

>> ll

At the top level we see a list of databases. When we have cd'd to database, we see a list of documents:

geoquiz >> ll

We can also add the starting letters of a document's id to narrow the list:

geoquiz >> ll do
dominican republic
geoquiz >>

Viewing the contents of a database

When at the top level, using cat shows a databases's stats:

>> cat geoquiz

When inside a database, cat shows the contents of a document:

geoquiz >> cat dover
{"_id":"dover","_rev":"1-7ea98285628d4bb3203a0ef3b1f34247","type":"Feature","properties":{"name":"Dover","group":"Shipping Forecast"},"geometry":{"type":"Polygon","coordinates":[[[0.439453125,50.83369767098071],[1.58203125,50.233151832472245],[1.494140625,50.84757295365389],[1.7578125,50.94458443495011],[2.48291015625,51.08282186160978],[2.9443359375,51.28940590271679],[1.3842773437499998,51.26191485308451],[1.29638671875,51.12421275782688],[1.03271484375,51.069016659603896],[0.9667968749999999,50.93073802371819],[0.791015625,50.958426723359935],[0.439453125,50.83369767098071]]]}}
geoquiz >>

Creating data

This is where the anaology of directories & files --> databases & documents is stretched. We use the echo command to generate data:

testdb >> echo '{"a":1,"b":2,"c":"three"}'
testdb >>

or we can specify the id by piping to a 'file':

testdb >> echo '{"a":1,"b":2,"c":"three"}' > mydoc
testdb >>

Touching data

You can create a new empty document, or 'touch' an existing one (load it and save it) by using touch:

test >> touch moo
test >> touch moo
test >>

Deleting data

We can remove documents with rm:

testdb >> rm mydoc
testdb >> 

or remove whole directories with rmdir:

>> rmdir test

Copying a document

When inside a directory (database), we can copy a document with:

testdb >> cp doc1 doc2

If the destination document is already there, we will get an error:

testdb >> cp doc1 doc2
409: Document update conflict.

Copying a database

When at the top of the directory tree, we can replicate one database to another with the cp commnand

>> cp databasea databaseb
Replication scheduled:

Replication happens asynchronously. We can check on its progress by using cat with the name of the target database:

>> cat databaseb

We can even replicate to and from a remote URL:

>> cp databasea
Replication scheduled:

Showing first few documents from a database

When at the top of the directory tree, we can output the first ten of a database's documents with head:

>> head geoquiz

Showing the revision history of a document

When inside a database (directory), you can see a visualisation of the revision history with tree:

A document with only one revision will simply show it's id and revision token:

testdb >> tree 87c8882011c89970bbe077ac67003479
id = 87c8882011c89970bbe077ac67003479
└─ 1-e14063a7ba34a22b100284ce731ad6ac *

A document with many conflicts on revision 1 will look like this:

testdb >> tree 87c8882011c89970bbe077ac67003479
id = 87c8882011c89970bbe077ac67003479
└─ 1
   ├─ 1-100785dab5598961c8588790a810d37c
   ├─ 1-1234cfba23d341a6d3916372a782fd65
   ├─ 1-16d159e554c289d5848a3ca8854f9807
   ├─ 1-1f10158068c458605d02ed0199ccd23b
   ├─ 1-45b83b90c5112878ad1a961b3e7ccaee
   ├─ 1-5e52a4558f111a53afe6ef72ee831af8
   ├─ 1-6a74408eb56ad564c1d461c97e3c47dc
   ├─ 1-6f49e763289e848f1650a94043a1e792
   ├─ 1-93b0bd6be8d346e28f95584a972c4e24
   └─ 1-94ec1c1571a5b00a5f0bf4121af1ddef *

And a more complicated revision history may look like this:

testdb >> tree 87c8882011c89970bbe077ac67003479
id = 87c8882011c89970bbe077ac67003479
├─ 1-46d69249075d3c7edebff00bb1eab65e
├─ 2-cc0b8b79af66fba84a8443484bff5160
├─ 3-52d91622d40f174894c567cc1fcee2e3
├─ 4
│  ├─ 4-5c58ab6c4a15f5b8b880994fa52dfa68
│  └─ 4-8171912e80397748fbde74cc09d42c6e
├─ 5-edec47733ea830362a5913b7f6312fe6
└─ 6
   ├─ 6-5f24a47d9c6cbd78261830ef179aebfd
   └─ 6-f564b9850dca8e61019aeabdd5480f3f *

The winning revision is marked with an asterisk.

Removing conflicts from a document

We can delete all conflicting revisions from a document (other than the winning revision) using fsck <id>:

mydb >> tree mydoc
id = mydoc
└─ 1
    ├─ 1-1a0f63dc5b1e38a31c3a42dbb4afe3db
    ├─ 1-5eb7c1177ad06bf192c3dacf776cf3d3
    ├─ 1-7c1dafbec62feefc2f0e875aea2f6093
    ├─ 1-94ec1c1571a5b00a5f0bf4121af1ddef
    ├─ 1-95630339bde96adda2be19207c4772c8
    ├─ 1-9d1d7a18212c0c74369208e4aef7fa13
    ├─ 1-d2701441808e0caee7c394d77fbe7550
    ├─ 1-da86decbdae0ef60ad41c33c12870860
    ├─ 1-e91608e02ae31b5c6085d5ca17d964e2
    └─ 1-f5401b77bb604d6f55c04a0e661f69d4 *
mydb >> fsck mydoc [{"ok":true,"id":"mydoc","rev":"2-96d4749bff11e619f31c3918671ec072"},{"ok":true,"id":"mydoc","rev":"2-0720b0ca56a1918feb5fac5bc0f5f7f6"},{"ok":true,"id":"mydoc","rev":"2-41e157d902abb4a9a84e8fcd905b17da"},{"ok":true,"id":"mydoc","rev":"2-421cc57d13e5f922fcc91f52e0884d3b"},{"ok":true,"id":"mydoc","rev":"2-da7d32f6a0201bf1509632d0f4b58359"},{"ok":true,"id":"mydoc","rev":"2-ef061a6709fa93bbc92f07277b81990a"},{"ok":true,"id":"mydoc","rev":"2-558011a4162d26bdcec71166556627c6"},{"ok":true,"id":"mydoc","rev":"2-19ffd7f841ddf020b42151d17f0012cc"},{"ok":true,"id":"mydoc","rev":"2-4d8e91ebc73462334b69a76610264799"}]
mydb >> tree mydoc
id = mydoc
└─ 1-f5401b77bb604d6f55c04a0e661f69d4 *

All of the conflicting revisions are deleted in a single bulk operation. You see the response to the bulk operation.

If we want to keep a specific revision (that is not current winning revision), then we can do fsck <id> <rev>:

mydb >> tree mydoc
id = mydoc
└─ 1
    ├─ 1-16d5fd150971e97f6adec5e17f515594
    ├─ 1-2d9097166eeaeffc5ae70346fea0b988
    ├─ 1-32616223ff8de17ee8a1afbcccc05e8e
    ├─ 1-36602b53bf2918b393b1bef3c7648767
    ├─ 1-49dedfaefc6f706b609bc75958499a13
    ├─ 1-94ec1c1571a5b00a5f0bf4121af1ddef
    ├─ 1-9e9b49aff3c1b99dcfa01e6292053aa9
    ├─ 1-a3eefcfb591f999b87284663a287d3b9
    ├─ 1-a7f639949923d35e26974b3b81522116
    └─ 1-a8f68832e5dd0acc1d24d099dceea335 *
mydb >> fsck mydoc 1-999
The revision 1-999 does not exist in the document.
mydb >> fsck mydoc 1-a7f639949923d35e26974b3b81522116
mydb >> tree mydoc
id = mydoc
└─ 1-a7f639949923d35e26974b3b81522116 *
mydb >> 

Showing the disk usage of a database

When at the top level, we can show the statistics of a database using du <dbname>:

>> du ebooks  

Similarly if we are inside a database, we can simply use du:

>> cd ebooks
ebooks >> du


  • force rmdir to require confirmation before deleting a database


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free