title: How to integrate CouchApp, Node.JS, Sammy and Mustache
body: <p>I set up a node.couchapp.js CouchApp and pushed it to my CouchDB. There is Sammy and jQuery included by default. Now, I'd like to add Mustache for templates, but don't exactly know where? I could use it as Node.js module or jQuery plugin.</p>
  
  <p>I started with some sample code, just to see if it works, but it doesn't:</p>
  
  <pre><code>ddoc.lists = {
  "basic": "function (head, req) { var that = this; provides('html', function () { var to_html = require('modules/mustache').to_html; var members = []; var row; while (row = getRow()) { members.push({club: row.key[0], name: row.key[1]}); } return to_html(that.templates['roster.mustache'], { members: members }); }) }"
  };
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>{"error":"invalid_require_path","reason":"Object has no property \"modules\". ...
  </code></pre>
  
  <p>Project structure is:</p>
  
  <pre><code>. Project
  | - app.js
  | - attachments
  | - - scripts
  | ` - index.html
  | - modules
  |   | mustache
  | - ` - mustache.js
  ` - templates
  </code></pre>
  
  <p><strong>Update</strong>
  I modified the code a bit and excluded the template folder as possible cause. This snippet is from a solved question here on SO, so it should actually work. But it's still the same error. I installed mustache.js with npm install mustache and renamed the folder from node_modules to modules (didn't work with node_modules either).</p>
  
  <pre><code>"basic": "function (head, req) { provides('html', function () { var template = '{{%IMPLICIT-ITERATOR}}{{name}}: &lt;ul&gt; {{#items}}&lt;li&gt;{{.}}&lt;/li&gt;{{/items}} &lt;/ul&gt;'; var mustache = require('./modules/mustache/mustache.js'); return mustache.to_html(template,view);});}"
  </code></pre>
  
  <p>But it's still the same error. </p>