N
N
ninja op op2020-05-20 14:02:10
JavaScript
ninja op op, 2020-05-20 14:02:10

How to return a value from an asynchronous function?

There is a function

function authcheck(from_id,first_name){
  conn.query("SELECT * FROM `users` WHERE `id` = '"+from_id+"'", function(err, results) {
      if (err){
          console.log(err); return false;}
      var result = JSON.parse(JSON.stringify(results));
      if ( result[0] === undefined ){
        conn.query("INSERT INTO `users` (`id`,`name`,`balance`) VALUES ('"+from_id+"','"+first_name+"','0');", function(err, results){
          if (err){
              console.log(err); return false; }
          return 'unf';
        });
        return false;
      }else{
        return ['jopa']
      }


  });
}


But no values ​​are returned from it. How to be?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question