1

I'm experiencing an issue when trying to connect to a MySQL database with Node.JS in my React Native application.

var mysql = require('mysql');

var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    port: 8889,
    database: "blabla"
}); 

con.connect(function(err) {
    if (err) console.log(err);
});

I can access to phpmyadmin without any problem (same user and password) but when I execute the JS file the terminal seems to load but stay stuck like this:

enter image description here

I don't think that there is a link with React but I really have no idea about it.

Thanks in advance for your help

0

2 Answers 2

2

According to the mysql docs: https://www.npmjs.com/package/mysql you need to add con.end(); after you are finished with the connection.

Sign up to request clarification or add additional context in comments.

Comments

0

I just understood that I didn't exit the script, but it's working (sorry).

The line to end the script for Node.js beginners like me:

process.exit()

1 Comment

Until the connection is closed (see Kodie Grantham's answer), Node will not exit the process itself. Once you close the connection, Node will exit too.

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.