Skip to content

Instantly share code, notes, and snippets.

@idx3d
Last active December 15, 2015 04:39
Show Gist options
  • Save idx3d/5203457 to your computer and use it in GitHub Desktop.
Save idx3d/5203457 to your computer and use it in GitHub Desktop.
Async Sample
function userExist(user, callback) {
db.connection.query('SELECT ...user...', function(err, rows) {
if (err) callback(err); // еще желательно проверять typeof колбека, функция ли это
if (rows) {
callback(null, true);
} else {
callback(null, false);
}
});
}
userExist('User', function (err, isExists) {
if (err) console.log(err.message);
console.log(isExists);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment