Find is not a function

1

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.

    
asked by Gonzalo Porelmundo 21.07.2016 в 20:48
source

1 answer

1

There is already a native function in JavaScript to make find   link maybe you can try that.

    
answered by 10.11.2016 в 19:36