I'm working with node js and in the model I get this error
TypeError: $ .find is not a function
I use jquery to do the find
models.Account.authenticate = function(login, password, cb){
var hashpass = common.hash(password, 'user.salt');
var $ = require('jquery');
$.find({where: { username: login }}).success(function(acc) {
//if (acc && acc.pass != password) acc = null;
if (acc && acc.pass != hashpass) acc = null;
if (cb) cb(acc);
}).error(function(err){
console.log(err);
});
}
The authenticate function is called from the controller to check if the user exists in the database.
// POST: /login
app.post('/login', function(req, res){ homeloginPost(req, res, {'api':false}); });
var homeloginPost = function (req, res, mode) {
models.Account.authenticate( req.body.user, req.body.pass, function(userFound) {
if (userFound) {
common.log(util.format( 'loginPost %s mode: %j', req.body.user, mode));
req.session.regenerate(function(err){
req.session.user = userFound;
if (mode.api) {
res.send({ok:true, user:userFound.name}); //json
} else {
res.redirect(req.body.redir || '/');
}
}); //session.regenerate
} else { //not userFound
common.log(util.format( 'loginPost DENIED %s mode: %j', req.body.user, mode));
common.sleep(4000, function(){
if (mode.api) {
res.send({ok:false, error:'Incorrect credentials'}); //json
} else {
req.flash('warn', 'Incorrect credentials');
res.redirect('/login');
}
});
}
});
};
I've already tried launching the installer command npm installer jquery and still giving the error.
I do not know why he tells me it's not a function.