couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan Ramage <>
Subject Re: Where does self-written CommonJS module go?
Date Tue, 26 Feb 2013 04:34:20 GMT
> If I write my own CommonJS module for use with a list,
> where does it go within a couchapp hierarchy?
I personally like putting them in 'views/lib/mylib.js'

That way they can be called from views as well (if needed). But if you are
sure they are only to be used in a list function, you can place them
anywhere in the design doc.

>  If it can be used
> for both server-side as well as www-side, where should
> it be placed?

This is a bit of a harder question for the following reasons:

 1) There is no way "get" a subsection of a design document. So from the
browser side you cant have a script tag (or some other module loader)
retrive the js code from about.
  2) You could have the code as an attachment to couchdb. This would solve
#1. But then you would not be able to require it in your list function. ie,
require('_attachmets/js/mylib.js') would never work.

So the workaround is either to put it in two places. Or to have a show
function that runs on your ddoc to retrieve parts that look like js files
to the browser.Lots of couchapp tools make this look easier. Not sure what
your are using, but just making sure you understand what is happening

As maybe some help, I have included a pretty versatile couch commonjs


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message