here is my complete code
var express = require(\'express\'), app = express(), mongoose = require(\'mongoose\'), bodyParser = require(\'body-parse
Your code is wrong in this place. You may see it.
var validPassword = user.comparePassword(req.body.password);
If you use bcryptjs thrid party plugins, like that
bcryptjs
let validPassword = bcrypt.compare(req.body.password, user.password);
bcrypt.compare(password, hashedPassword);