app.post('/login', function (req, res) {
var login = req.body.login;
var pass = req.body.pass;
var ret = CheckUserValid(login, pass);
res.send(ret);
})
function CheckUserValid(login, pass,callback) {
var sql = "SELECT * FROM `user` WHERE login = ? AND pass= ?";
client.query(sql, [login, pass], function selectResutl(err, results, fields) {
console.log(results);
if (!err) return true;
else
throw err;
});
}
first Function is about request and second is about making call to mysql. because it’s async so it’s not worked.
Can someone let me know how I can make it work synchronously like in C#.
The signature of your
CheckUserValidmethod already implies acallback.You can use that to call something when your db-request is done, like this:
By convention you should pass the
erras first argument, but in the end that’s up to you.However you can pass the original error up to your initial function and handle it there.