NOTE: Action.js has been removed from CouchDB trunk as it is more than we want to support right now. That said, it is still a good way to learn how to write your own external servers. For the time being, action.js can be found here: [WWW]

See also: ExternalProcesses

Actions are a default included functionality that is made available by the new ExternalProcesses feature. _design/ docs can now specify an actions member that is an object of key/function pairs.

Action functions are specified in JavaScript and have access to a CouchDB object that can make requests to the database.

Example ''_design/'' Document

    "_id": "_design/an_action",
    "actions": {
        "times_two": "function(req, db) {return {code:200, json: {val: req.query.q * 2}};}"

By default, this action is available at the URL:

Example Using the Database

The db argument is a CouchDB instance. This class is defined in couch.js at:

For now the best references on the API are couch.js itself, and couch_tests.js that exercises it and most of CouchDB.

    _id: "_design/with_db",
    actions: {
        "get" : "function(req, db) { var doc =; return {json:doc} }",

Accessed via:"_design/with_db"


The actions functionality is still a bit rough around the edges and there are efficiency questions on the implementation. Also, the error reporting is sub-par (to say the least...).

That said, it helps serve as a reference (and testable) example of _external.

last edited 2008-12-30 21:07:28 by ChrisAnderson