0
let salt;
    db.all(
      `SELECT salt FROM users WHERE username = ?`, [username],
      (err, row) => {
        if (err) throw err;
        salt = row[0].salt;
        console.log(' SALT: ' + salt + 'saltEND');
      }
    )
    console.log(' SALT: ' + salt + 'saltEND2');

The correct row information is being outputted in console.log(' SALT: ' + salt + 'saltEND'); but not in saltEND2

BHughes
  • 23
  • 6
  • 1
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Reyno Apr 06 '23 at 13:21
  • @BHughes `db.all()` is asynchronous function which means it takes some time while the synchronous functions run, so your "saltEND2" log logs the current value of `salt` which is `undefined` – Aleksandar Apr 06 '23 at 14:58
  • @Aleksandar Oh that makes sense! any suggestions, maybe a timeout function? – BHughes Apr 07 '23 at 15:20

0 Answers0