R
R
Roman2019-02-02 10:54:09
MySQL
Roman, 2019-02-02 10:54:09

When creating a db connection using node js, nothing happens. Why doesn't it throw an error?

This is my code:

var mysql = require('mysql');
 
console.log('Get connection ...');
 
var conn = mysql.createConnection({
  database: 'test',
  host: "localhost",
  user: "root",
  password: "",
});
 
conn.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

console.log('111');

The console outputs:
> node ./test.js
Get connection ...
111

I tried to connect with incorrect parameters to cause at least some kind of error, but without success.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2019-02-02
@BorisKorobkov

Add error handling:

process
  .on('uncaughtException', err => {
    console.error(err, 'Uncaught Exception thrown');
    process.exit(1);
  });

R
Roman, 2019-02-02
@RomanTrakhtenberg

a little further there was an interrupt,
I didn’t have time to get a response from the database ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question