'Save data found from mysql to local variable [duplicate]

I'm trying to save the returned data from MySQL to a local variable,

This is what I tried

  const queryUser = "SELECT * FROM Users WHERE email = ?";
  var userFound;
  db.query(queryUser, [email], (err, result) => {
    userFound = result;
    (result returns an array with one object on it)
   });
  console.log(userFound) returns undefined;

But it's returning me undefined



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source