I'm making an app with React and Express, and I'm facing a basic issue. I've created a let maxPlayers = 0; Then I call my DB to find the actual max players number :
let maxPlayers = 0;
// Here I ask my DB to count my players
db.query("SELECT * FROM cards", (err, rows) => {
console.log(rows.length) // -> 30
maxPlayers = rows.length // In my logic, 0 becomes 30
console.log(maxPlayers) // -> 30
});
console.log(maxPlayers) // -> 0
What I want is myMaxPlayers to be set as 30 outside the db.query function.
I know this is a basic scope issue, but I've tryied everything i know and i struggle.