0
Following this tutorial of Vedovelli about Ode with restify and mysql, I implemented on the server with pm2.
Only after a few days the connection began to be refused
Is showing that message:
errno: 'ECONNREFUSED',
code: 'ECNNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR
The error is giving in this part here, in the file auth.js:
authenticate: (email, password) => {
return new Promise((resolve, reject) => {
const {connection, errorHandler} = deps
const queryString = 'SELECT id, email FROM users WHERE email = ? AND password = ?'
const queryData = [email, sha1(password)]
connection.query(queryString, queryData, (error, results) => {
if (error || !results.length) {
errorHandler(error, 'Falha ao localizar o usuário', reject)
return false
}
const {email, id} = results[0]
const token = jwt.sign({email, id}, process.env.JWT_SECRET, { expiresIn: 60 * 60 * 24 })
resolve({token})
})
})
}
My whole project is here if you want to look
Strange that on localhost works
What is the name of this file that you submitted the code for?
– Sorack
Actually looking now here the error, the port is 3306, ie your server’s
Node.js
is unable to connect toMySQL
– Sorack
Is the file auth.js
– adventistaam
Can you check if the connection to the
MySQL
is functioning byWorkbench
on that machine?– Sorack
I can try, just a moment
– adventistaam
Yes can connect
– adventistaam
But look, you’re trying to connect to the ip address
127.0.0.1
, I understand from your reply the address of theMySQL
it’s another, I’m wrong?– Sorack
Yes it’s another one. It’s all set up to the correct ip, but it shows this one. I think it must be because it’s where it’s from, I don’t know
– adventistaam
Let’s go continue this discussion in chat.
– adventistaam
It is a fact that the problem is that the
Node.js
cannot connect to this port ofMySQL
, but the only thing I can tell you is that you execute the commandtelnet localhost 3306
to prove it. As resolution I don’t have much idea– Sorack
Um... as you said, I think the process.env.DB_HOST line that comes from the file . env is not getting the host
– adventistaam
Puts a
console.log
on the object you use onmysql.createConnection
to check out this– Sorack
I gave a
console.log
in theprocess.env.DB_HOST
and gaveundefined
– adventistaam
I called you for discussion in chat. Take a look there
– Sorack