Simply doing callback(...)
does not end the execution of the function; you need a return statement to tell the function to stop running, as seen below:
function authenticate(username, password, callback) {
var query = "SELECT * from mydb.users where username='" + username + "'and BINARY password='" + password + "'";
connection.query(query, function (err, rows) {
if (rows[0] != undefined) {
if ('username' in rows[0]) {
if (rows[0].username == username) {
return callback(true);
}
}
}
return callback(false);
});
};
You will see this technique used when you read other NodeJS code.