I am Node.js beginner coming from a PHP background.
I am using mysql, module node-mysql (Github: felixge/node-mysql) and unfortunately it is async.
The debug line "__2" came before "__1", so the function returns before the query occurs.
What should I do ?
var db = require('../classes/db.js')
var method = Usuario.prototype;
function Usuario() {
    // constructor
}
method.doAuth = function(usuario, senha) {
    var retorno = 0
    var sql = 'SELECT * from `tb_usuario` WHERE `usuario` = ? and `senha` = ?'
    db.query(sql, [usuario, senha], function(err, rows, fields) {
    if (err) throw err
    console.log("__1")
    if(rows.length > 0)
        retorno = rows[0].id        
    })
    console.log("__2")
    return retorno
}
module.exports = Usuario
 
     
     
    