I got this error when I tried to connect to the mysql database -
{ errno: -111, code: 'ECONNREFUSED', syscall: 'connect',
address: '127.0.0.1', port: 3306, fatal: true }
I used the same host, user and password as when I am using popsql which works.
const databasePassword = process.env.DATABASE_PASSWORD
const mysql = require('mysql');
function saveIDInformation(titleID){
let savingStatus = "passed"
const con = mysql.createConnection({
host: "localhost",
user: "root",
password: databasePassword,
database: "idmarketplace",
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
const IDinformation = `INSERT INTO idInformation(titleID) VALUES(${titleID});`;
con.query( IDinformation,(err, result)=> {
if (err) {
savingStatus = "query error";
throw err;
}
console.log("Data inserted");
});
});
return{
status: savingStatus
}
}
exports.saveIDInformation = saveIDInformation;
I research this error in github, stackoverflow, chatGPT and other websites. Furthermore, I also watched Youtube to solve this problem, but I still can't find the solution.