1

Is there a way to import "external" Javascript libraries for use in List Functions in CouchDB? I am trying to build a List Function that will perform a XSL Transformations and I was hoping to be able to use the Sarissa library.

EDIT: Please see my related question about XSL Transformations in CouchDB.

Community
  • 1
  • 1
lalibi
  • 3,057
  • 3
  • 33
  • 41

2 Answers2

2

You'll need to add the source files of the library to your design document. (assuming it's a JS library) How you do that depends on many factors, plus you didn't specify how you're deploying to your CouchDB instance, so I'll just sidestep that for now.

The point is you can share code with list functions (among some others like map functions) as CommonJS modules. If you load the source file into a string that is stored in your design document, you can use the exported library via require("lib/sarissa") for example.

Dominic Barnes
  • 28,083
  • 8
  • 65
  • 90
1

If the library is compatible with CommonJS, you can include it with:

function(head, req) {
  var Sarissa = require("lib/sarissa");
  ...
}

If not, you can include it with couchapp precompiler:

function(head, req) {
  // !code lib/sarissa.js
  ...
}
Aurélien Bénel
  • 3,775
  • 24
  • 45