You will need to make this.isNotDuplicate
asynchronous. Try something like this:
this.isNotDuplicate = function(email, callback) {
var query = user.findOne({ 'email': email })
query.exec(function(err, user) {
if (err) {
console.log(err)
callback(err)
} else {
console.log(user)
cb(null, !!user)
})
}
And then when checking for the user:
this.signUpUser = function(user) {
this.isNotDuplicate(user.email, function(err, exists) {
if (err || exists) {
response['error'] = true
response['message'] = (exists) ? 'duplicate email' : 'error'
} else {
// continue doing whatever needs to be done
}
})
}