title: TypeError: User is not a constructor - Mongoose Node.js Express-Validator
body: <p>I got this error: </p>
  
  <blockquote>
    <p>"User is not a constructor TypeError"</p>
  </blockquote>
  
  <p>I couldn't find out what is wrong in the code. Any advice is appreciated!!</p>
  
  <p><strong>routes/users.js</strong></p>
  
  <pre><code>// Initialised user.js into users.js
  // var User = require('../models/user');
  
  if (errors) {
      // code here is working
  } else {
      console.log('PASSED'); // logs "passed" msg successfully
      var newUser = new User({
          name: name,
          email: email,
          phone: phone,
          password: password2
      });
  
      User.createUser(newUser, function (err, user) {
          if (err) throw err;
          console.log(user);
      });
  
      req.flash('success_msg', 'You had been succesfully registered! Try signin.');
      res.redirect('/users/signin');
  }
  </code></pre>
  
  <p><strong>models/user.js</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  var bcrypt = require('bcrypt');
  
  var UserScheme = mongoose.Schema({
      name: {
          type: String,
          index: true
      },
      email: {
          type: String
      },
      phone: {
          type: String
      },
      password: {
          type: String
      }
  });
  
  var User = module.export = mongoose.model('User', UserScheme);
  
  // encrypting password into hash
  module.export.createUser = function(newUser, callback){
      bcrypt.genSalt(saltRounds, function(err, salt) {
          bcrypt.hash(newUser.password, salt, function(err, hash) {
              newUser.password = hash;
              newUser.save(callback);
          });
      });
  };
  </code></pre>
  
  <p>I can update the post if more code is necessary.</p>