title: File Structure of Mongoose & NodeJS Project
body: <p>I currently have all my models (Schema definitions) in the /models/models.js file for my Mongoose/NodeJS application. </p>
  
  <p>I'd like to break these apart into different files as such: user_account.js, profile.js, etc. However I cannot seem to do so as my controllers break and report back "<strong>cannot find module</strong>" once I pull these classes apart. </p>
  
  <p>My project structure is as follows: </p>
  
  <pre><code>/MyProject
    /controllers
      user.js
      foo.js
      bar.js
      // ... etc, etc
    /models
      models.js
    server.js
  </code></pre>
  
  <p>The contents of my models.js file looks like this: </p>
  
  <pre><code>var mongoose = require('mongoose'),
      Schema = mongoose.Schema,
      ObjectId = Schema.ObjectId;
  
  mongoose.connect('mongodb://localhost/mydb');
  
  var UserAccount = new Schema({
      user_name       : { type: String, required: true, lowercase: true, trim: true, index: { unique: true } }, 
      password        : { type: String, required: true },
      date_created    : { type: Date, required: true, default: Date.now }
  }); 
  
  var Product = new Schema({
      upc             : { type: String, required: true, index: { unique: true } },
      description     : { type: String, trim: true },
      size_weight     : { type: String, trim: true }
  });
  </code></pre>
  
  <p>My user.js file (controller) looks like this: </p>
  
  <pre><code>var mongoose    = require('mongoose'), 
      UserAccount = mongoose.model('user_account', UserAccount);
  
  exports.create = function(req, res, next) {
  
      var username = req.body.username; 
      var password = req.body.password;
  
      // Do epic sh...what?! :)
  }
  </code></pre>
  
  <p>How can I break the schema definition into multiple files and also reference it from my controller? When I do reference it (after the schema is in a new file) I get this error: </p>
  
  <p>*Error: Schema hasn't been registered for model "user_account".*</p>
  
  <p>Thoughts? </p>