title: Cannot overwrite `users` model once compiled node js
body: <p>I am getting this error while compiling my code </p>
  
  <pre><code>throw new mongoose.Error.OverwriteModelError(name);
        ^
  OverwriteModelError: Cannot overwrite `users` model once compiled.
  </code></pre>
  
  <p>This is my Model/users.js file</p>
  
  <pre><code>const mongoose = require('mongoose');
  const bcrypt = require('bcryptjs');
  const config = require('../config/database');
  
  //User Schema
  const UserSchema = mongoose.Schema({
    name: {
      type:String
    },
    email: {
      type:String,
      required:true
    },
    username: {
      type:String,
      required:true
    },
    password: {
      type:String,
      required:true
    }
  });
  
  const users = module.exports = mongoose.model('users',UserSchema);
  
  module.exports.getUserById = function(id,callback)
  {
    User.findById(id,callback);
  }
  
  module.exports.getUserByUsername = function(username,callback){
    const query = {username: username}
    user.findOne(query,callback);
  }
  module.exports.addUser = function(newUser,callback){
    bcrypt.genSalt(10,(err,salt)=&gt;{
      if(err)
      {
        throw err;
      }
      bcrypt.hash(newUser.password,salt,(err,hash)=&gt;{
        newUser.password=hash;
        newUser.save(callback);
      });
    });
  }
  </code></pre>
  
  <p>This is my route/users.js file</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const passport = require('passport');
  const jwt = require('jsonwebtoken');
  var Log = require('log')
    , log = new Log('info');
  
  const User = require('../Model/users');
  //const ap = express();
  
  //Register router
  router.post('/register',(req,res,next)=&gt;{
    log.info('entering register');
    let newUser = new User({
      name:req.body.name,
      email:req.body.email,
      username:req.body.username,
      password:req.body.password
    });
    User.addUser(newUser,(err,user)=&gt;{
      log.info("inside add user");
      if(err){
        log.error('error while registaring ' + err);
        res.json({success:false,msg:'failed to register user'});
      }
      else {
        res.json({sucess:true,msg:'user registered succefully'});
      }
    })
  });
  router.get('/authenticate',(req,res,next)=&gt;{
    res.send("authenticated");
  });
  router.get('/profile',(req,res,next)=&gt;{
    res.send('profile');
  });
  module.exports=router;
  </code></pre>
  
  <p>passport.js</p>
  
  <pre><code>const JwtStrategy = require('passport-jwt').Strategy;
  const ExtractJwt = require('passport-jwt').ExtractJwt;
  const User = require('../model/users');
  const config = require('../config/database');
  
  module.exports = function(passport){
    let opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
    opts.secretOrKey = config.secret;
    passport.use(new JwtStrategy(opts,(jwt_payload,done)=&gt;{
      User.getUserById(jwt_payload._id,(err,user)=&gt;{
        if(err)
        {
          return done(err,false);
        }
        if(user){
          return done(null,user);
        }
        else {
          return done(null,false);
        }
      })
    }));
  }
  </code></pre>
  
  <p>I have tried suggestion from [<a href="https://stackoverflow.com/questions/19051041/cannot-overwrite-model-once-compiled-mongoose][1]">Cannot overwrite model once compiled Mongoose</a>
  but I am not able to understand what the problem is.</p>