Connection being refused

Asked

Viewed 1,101 times

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

inserir a descrição da imagem aqui

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?

  • Actually looking now here the error, the port is 3306, ie your server’s Node.js is unable to connect to MySQL

  • Is the file auth.js

  • Can you check if the connection to the MySQL is functioning by Workbench on that machine?

  • I can try, just a moment

  • Yes can connect

  • But look, you’re trying to connect to the ip address 127.0.0.1, I understand from your reply the address of the MySQL it’s another, I’m wrong?

  • 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

  • It is a fact that the problem is that the Node.js cannot connect to this port of MySQL, but the only thing I can tell you is that you execute the command telnet localhost 3306 to prove it. As resolution I don’t have much idea

  • Um... as you said, I think the process.env.DB_HOST line that comes from the file . env is not getting the host

  • Puts a console.log on the object you use on mysql.createConnection to check out this

  • I gave a console.log in the process.env.DB_HOST and gave undefined

  • I called you for discussion in chat. Take a look there

Show 9 more comments

1 answer

1


As described in your question (by the error returned) your server is trying to connect to the database on localhost, check if the object with the connection settings is with the correct information in the function call mysql.createConnection.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.