Changing the value of a variable within a nodejs function

Asked

Viewed 67 times

0

userFoundId = undefined;
    const result = connection.query('SELECT id FROM users WHERE name = :name and 
    password = :password', data, (err, result) => {
        userFoundId = result[0].id //Valor alterado para 1
    });
connection.end();
console.log(userFoundId) //Display undefined

How can I perform a user search inside the mysql database and the result of the query be saved in the userFoundId variable that will be used to log in?

No answers

Browser other questions tagged

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