When I simply run this code:
var mysql = require('mysql');
class Data {
static getAllData() {
console.log("Getting all data...")
var con = mysql.createConnection({
host: "localhost",
user: "myusername123",
password: "mypassword123",
database: "mydatabase"
});
con.connect(function (err) {
if (err) throw err;
var sql = "SELECT * FROM table";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result);
});
});
}
}
Data.getAllData()
My static method call works, it outputs all the RowDataPacket objects required.
However when I export this class using module.exports.Prompt = Prompt and then call the static method from a different file (I added return result to the method), the code within the con.connect doesn't even seem to run. As in, nothing is returned and nothing is printed out to the console.
Then I just copied the prompt class code into the file I wanted to use it in and then called it in a socket.on('message', data => {}) function and somehow it doesn't seem to work even though it's the same code just in a different file.
Any ideas?