Pelo amor de deus, já passei mais de 4 horas rodando na internet a solução desse erro e simplesmente não encontro:
servidor rodando na porta 3000
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1136:16)
--------------------
at Protocol._enqueue (C:\Users\alder\OneDrive\Projetos Node\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\alder\OneDrive\Projetos Node\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\alder\OneDrive\Projetos Node\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (C:\Users\alder\OneDrive\Projetos Node\Api_com_express_e_MySQL\index.js:6:9)
at Module._compile (internal/modules/cjs/loader.js:1139:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
at Module.load (internal/modules/cjs/loader.js:988:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
Segue o código
const customExpress = require ('./config/customExpress');
const conexao = require ('./infraestrutura/conexao'); //chamando a conexao com o mysql
conexao.connect (erro =>
{
if (erro) {
console.log (erro)
}
else
{
console.log (`conectado com sucesso`)
}
})
const app = customExpress ();
app.listen (3000,() => console.log('servidor rodando na porta 3000'));
const mysql = require ('mysql') //chamando o mysql
const conexao = mysql.createConnection ({ //coloca as bases da conexão
host: '127.0.0.1',
porta: 3307,
user: 'root',
password: 'adm',
database: 'agenda-petshop'
})
module.exports = conexao;