title: mongoose: TypeError: [function name] is not a function. when trying to create mongoose instanse
body: <p>I'm writing a web application with MEAN stack, and I'm getting a headache with mongoose instance.</p>
  
  <p>Here are (piece of) my codes:</p>
  
  <p><strong>my route</strong></p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var accDocService = require('../services/accdoc-services');
  
  router.post('/dailybook', function(req, res) {
     accDocService.addAccDoc(req.body, function(error) {
        if (error) throw error;
     });
  });
  </code></pre>
  
  <p><strong>accdoc-service.js</strong></p>
  
  <pre><code>var accDoc = require('../models/accdoc').accDoc;
  
  console.log(typeof accDoc);
  
  exports.addAccDoc = function(accDoc, next) {
     var newAccDoc = new accDoc({
        number: '45645'
     });
  
     newAccDoc.save(function(error) {
        if (error) throw error;
        console.log("doc created");
     });
  };
  </code></pre>
  
  <p><strong>accdoc.js (the model file)</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var accDocSchema = new Schema({
     number: String
  });
  
  var accDoc = mongoose.model('accDoc', accDocSchema);
  
  module.exports = {
     accDoc: accDoc
  };
  </code></pre>
  
  <p>After sending the post request, I'm getting <code>TypeError: accDoc is not a function</code></p>
  
  <p>Also, <code>console.log(typeof accDoc);</code> in second file, returns <em>function</em>.</p>
  
  <h2>EDIT 1</h2>
  
  <p>In <strong>accdoc-services</strong>, if I move <code>var AccDoc = require('../models/accdoc');</code> to the <code>addAccDoc</code> function, everything works fine.</p>
  
  <p>Am I missing some node.js stuff here? I'm watching a tutorial video from Lynda that there is not some <em>scope</em> problem like this.
  <a href="http://pasteboard.co/2eujSsa5.png" rel="nofollow">here is an image from Lynda tutorial</a></p>