0
    function checkMYSQL()
{
    var mysql = require('mysql')
    var connection = mysql.createConnection({
    host: "------",
    user: "-----", //
    password: "-----", //
    database: "-----",
    })
    var resultsss = connection.connect((err) => {
        if (err) {
          console.log(err)
          return
        }
        console.log('Database connected')
      })
    return 1;
}

okay so I've got this function to connect to a remote mysql database however it just skips and doesn't output anything (doesn't reach console.log(err) or ('Database connected')

this is the connection variable when debugging and results is undefined

I would really appreciate any help possible, thank you.

1 Answers1

0

I guess your problem is that you don't call this function on server start. So insert this function into server.start/listen whether you are using express or pure node.js

Dawid
  • 144
  • 1
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '23 at 13:52