title: Nodejs + CoffeeScript + Mongoose : Define Module?
body: <p>I'm trying to create a little application to store snippets of code using nodejs and mongodb 
  I'm using Coffeescript to write the app.</p>
  
  <p>The problem is, i want to separate the code in modules
  so i create this folder structure</p>
  
  <pre><code>/app
      /lib
          /models
          /routes
      core.coffee
  </code></pre>
  
  <p>The core.coffe is the "server" app using expressjs
  so in this file i have</p>
  
  <pre><code>mongoose = module.exports.mongoose = require 'mongoose'
  app      = module.exports.app   = express.createServer()
  Snippet  = module.exports.Snippet = require __dirname+'/lib/models/Snippet'
  #App configurations
  routes  = require(__dirname+'/lib/routes/general')
  </code></pre>
  
  <p>In lib/models/Snippet</p>
  
  <pre><code>mongoose = module.parent.exports.mongoose
  Snippet = new mongoose.Schema
      title:
          type: String
          default:'Title'
  
  mongoose.model 'Snippet',Snippet
  exports.Snippet = mongoose.model 'Snippet'
  </code></pre>
  
  <p>In /lib/routes/general.coffee</p>
  
  <pre><code>app      = module.parent.exports.app
  mongoose = module.parent.exports.mongoose
  Snippet  = module.parent.exports.Snippet
  
  app.get '/test', (req,res)-&gt;
      snip = new Snippet()
      res.send snip
  </code></pre>
  
  <p>But this don't work i get the following error message</p>
  
  <pre><code>TypeError: object is not a function
  at Object.CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
  </code></pre>
  
  <p>How can I accomplish that?</p>