I spend more than 6 hours searching and testing, I get frustrated, angry and you know... just for 3 minutes job.
Here it's my success story with incredible persistant Node.js error connect ECONNREFUSED .
Usual errors, maybe 3-4 minutes. I changed host: 'localhost' to host : '127.0.0.1', port: 8080, or maybe 8000, oh yes, 3306 this is. No, not that. Oh, yes, hostname: '127.0.0.1:3306'. No. Adding database, remove database. Change every thing I can now change. Nothing.
Maybe it is the port 8443. node app.js enter, connect ECONNREFUSED. no, it's not the port. No password, no root, no port. What can solve this?
OOhh, yes, I know, I should thinking about that. Maybe I need to put the project in root XAMPP root folder. No.
3 hours later. I need more music.
Unfortunately it was not the case.
Starting to find the real solution in my case
And after I read Yannick Motton's best answer on post host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server I found the solution.
1. Create an user with password, and grant all provileges
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON . TO 'username'@'localhost' WITH GRANT OPTION;
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON . TO 'username'@'%' WITH GRANT OPTION;
This will set user: username and pass: password
2. Change localhost with your XAMPP IP (and also add username/password for user and password)
Change host: "localhost" to host:"192.168.64.2", and update with user: "username", password: "password".
node app + enter
Connection established It's done. Hooray.
Hope this article will help you to solve the connect ECONNREFUSED error and to connect Node.js with phpMyAdmin in just a few minutes.
“Patience, persistence, and perspiration make an unbeatable combination for success.” - Napoleon Hill