I am trying to connect to a MySQL database using the following video: https://www.youtube.com/watch?v=f5kye3ESXE8. My app.js file is as follows:
const express = require('express');
const bodyParser = require("body-parser");
const mysql = require('mysql');
const app=express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
//MySQL
const pool=mysql.createPool({
connectionLimit : 10,
host : 'localhost',
user: 'root',
password: '',
database: 'nodejs_beers'
})
//want to be able to get all beers in the database
app.get('', (req, res) => {
pool.getConnection((err, connection) => {
if(err) {
console.log(err)
}
//query(sqlString), callback
connection.query('SELECT * from beers', (err, rows) => {
connection.release() //release the connection to pool
if(!err){
res.send(rows)
}
else{
console.log(err)
}
})
})
})
//make sure app is listening on 5000
app.listen(5000, () => console.log(`listen on port 5000`));
I've followed the video exactly, but I'm getting the following error when I attempt to enter "localhost:5000" into a browser:
[nodemon] starting `node app.js`
listen on port 5000
Error: connect ECONNREFUSED 127.0.0.1:3306
I've looked at xampp mysql doesn't run on port 3306 but I don't know how to get XAMPP to run MySQL on another port, and I can't find a my.cnf file to try and change it (if that is how it is supposed to be changed). I'm on MacOS Catalina and the XAMPP version is 7.4.2
I should also note that whenever I enter "localhost:8080" into a web browser, I'm brought to the "Welcome to XAMPP" page, which I believe means the Apache server is running correctly. I've double checked and I've got all 3 services running on XAMPP (Apache, MySQL, and ProFTPD).