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 couch-compile with all npm packages installed. Try it out:

var couchCompile = require("couch-compile")

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

couch-compile v1.4.0

Build CouchDB documents from fs.


Build CouchDB documents from directory, JSON or module.


var compile = require('couch-compile');
compile('/my/couch/app', function(err, doc) {
  // push


compile(directory, [options], callback)


When options.multipart is true, attachments are handled as multipart.


callback is called with two arguments: error and doc. In case options.multipart is set, callback is called with a third argument: attachments. This is a multipart attachments array as required by nanos db.multipart.insert:

  name: 'rabbit.png',
  content_type: 'image/png',
  data: <Buffer>

data can be a Buffer or a String.


A simple commandline client is included:

npm install -g couch-compile

Give it a directory, or use the current one:

couch-compile /my/couch/app

The Couch Directory Tree

couch-compile uses a filesystem mapping similar to Couchapp python tool and Erika: The Couchapp Filesystem Mapping.

It is quite self-explanatory. For example:

├── _id
├── language
└── views
    └── numbers
        ├── map.js
        └── reduce.js


  "_id": "_design/myapp",
  "language": "javascript",
  "views": {
    "numbers": {
      "map": "function...",
      "reduce": "function..."

See test/fixtures and test/expected for usage examples.

File Extensions

For property names file extensions will be stripped:

  "validate_doc_update": "content of validate_doc_update.js",


Files inside the \_attachments directory are handled special: They become attachment entries of the form

  "a/file.txt": {
    "data": "SGVsbG8gV29ybGQhCg==",
    "content_type": "text/plain"

The content\_type is computed using mime. data is the base64 encoded value of the file.

Read more about Inline Attachments.


Run the testsuite with

npm test

(c) 2014 Johannes J. Schmidt, TF
MIT License

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