How do I assign the connection.query result to a global variable?

0

I'm learning to use the mysql module of the node and I came across a situation where I can not assign the result to a global variable, follow my code:

let data = 0

  connection.query(query, (err, rows, fields) => {
    if (err) {
      console.log('An error ocurred performing the query.')
      console.log(err)
      return
    }

    data = rows
  })

If I print the variable data the result is zero, how do I assign the result to it?

obs: I used this example documentation.

    
asked by anonymous 18.04.2018 / 16:13

0 answers