title: How to organize code / logic with node.js / Express 3, and Mongoose (MongoDB)
body: <p>I see lots of examples where node.js / express router code is organized like this:</p>
  
  <p>// server.js</p>
  
  <pre><code>var cats = require('cats');
  app.get('/cats', cats.findAll);
  </code></pre>
  
  <p>// routes/cats.js</p>
  
  <pre><code>exports.findAll = function(req, res) {
      // Lookup all the cats in Mongoose CatModel.
  };
  </code></pre>
  
  <p>I'm curious if it would be okay to put the logic to create, read, update and delete cats in the mongoose <code>CatModel</code> as methods? So you could do something like <code>cat.findAll();</code> The model might look something like this:</p>
  
  <pre><code>var Cat = new Schema({
     name: {
       type: String,
       required: true
     }
  });
  
  Cat.methods.findAll = function(callback) {
     // find all cats.
     callback(results);
  }
  </code></pre>
  
  <p>Then you could use this in your router:</p>
  
  <pre><code>app.get('/cats', cats.findAll);
  </code></pre>
  
  <p>If if further logic / abstraction is needed (to process the results) then one could do it in <code>routes/cats.js</code>.</p>
  
  <p>Thanks in Advance.</p>