1

After creating a simple connection and making sure it works (give it wrong info and it throws an error) I went ahead and tried to query but upon doing so, the server just hangs, no error.

Here is the snippet:

var db = mysql.createConnection({
  host     : config.host,
  user     : config.user,
  password : config.password,
  port     : config.port,
  database : config.database
});

db.connect();

db.query("SELECT 1", function(err, rows) {
  console.log(rows);
});

Is there an error with the connection? How could I catch it if so?

3 Answers 3

1

You probably have an uncaught exception. try this:

process.on('uncaughtException', function (error) {
   console.log(error.stack);
});
Sign up to request clarification or add additional context in comments.

2 Comments

I did, still just hangs. I assume this should go after the db.query call, right? Not inside the callback
Yes. it's only related with nodejs internal (process module) so you can call it on top. and not in any callbacks.
1

Turns out, it was the connection after all. In case someone else gets this weird error, there are none to report because it's the connection to the server which hangs. It happens that the password had gotten turned into an integer instead of a string and this plus the "port" field make it hang. If I remove the port field, it immediately throws a connection denied error.

So, for future reference, if the connection hangs, try connecting using a db string instead and if that works, check that every field in this object is a string.

Comments

0

You can check like this:

connection.connect(function (err) {
    if (!err)
        console.log("conncetd");
    else
        console.log(err + "There is problem");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.