I did look at felixge/node-mysql library and didn't see a reference to the command client.connect in the API. Is this the actual call you're trying to make (not trying to be nitpicky here)? Regardless, IMHO you need to think more about how Javascript is designed, because it uses a programming paradigm different than most other popular languages.
The first issue I see in your code is that you haven't defined the callback, so it doesn't actually exist. I'd assume console.log(callback) is undefined. From your code, the anonymous function is the 'callback' for the client.connect function. You have to define what you are calling 'callback' at a higher scope. For example, I will define a function myCallback to exist in the scope higher than the client.connect's anonymous function. It may be useful to lookup Javacscript variable scope.
var myCallback(err, response) {
if (err) {
console.log('err:%s',err);
} else {
console.log('response:%s',response);
}
}
client.connect(err, function(response) {
// this anonymous function is the callback to client.connect, the var
// 'callback' would be undefined.
if (err) {
myCallback(err);
return; // Explicit call to return, else the lines below would run.
}
myCallback(null, response);
});
Second, if you do not explicitly call return within Javascript, the function will continue to process. I was bitten by this myself. Finally, Javascript runs an event-driven loop meaning it will never wait for functions to return a value, which is why we have all these callbacks in the first place. You can force Javascript to behave differently, for example by using a while loop until a condition is true. See the 'async' library by caolan, for various strategies of manipulating the event loop. The major disadvantage to overusing these methods is your actually wasting CPU cycles/blocking when you probably should use more callbacks and simply re-think how your programs works.