title: cannot retrieve this.lastID
body: <p>I'm using node, javascript, vscode, sqlite3.  I'm trying to grab the rowid after I insert a game record so I can use that as a foreign key to insert the details of the game.  The record inserts, and this.lastID contains the rowid but no matter how I try my copy of rowid erases itself as soon as this.lastID goes out of scope.</p>
  <pre><code>//databaseinterface.js
  function InsertNewGame() {
      let returnvalue;
      db.run(&quot;INSERT INTO Games DEFAULT VALUES&quot;, function(err) {
          if (err) {
            console.log(err.message);
          }
          // get the last insert id
          else {
            returnvalue = this.lastID;
  console.log (&quot;return value set at &quot; + returnvalue);
          }
      });
      console.log(&quot;but at the end of insertnewgame return value is: &quot; + returnvalue);
      return returnvalue;     
  
    };
  module.exports.InsertNewGame = InsertNewGame;
  
  //postheader.js
  var express = require('express');
  var bodyParser = require('body-parser');
  const Database = require('../public/javascripts/databaseinterface');
  var router = express.Router();
  router.use(bodyParser.json()); 
  
  router.post('/', function(req, res, next){
      
      let gameid = Database.InsertNewGame();  
      console.log(&quot;over in the router there is no sign of the returnvalue: &quot; + gameid)
      res.send(&quot;Game &quot; + gameid + &quot; inserted&quot;);
  });
  module.exports = router;
  </code></pre>
  <p>In the console I get:</p>
  <p>but at the end of insertnewgame return value is: undefined</p>
  <p>over in the router there is no sign of the returnvalue: undefined</p>
  <p>return value set at 16</p>
  <p>why is returnvalue resetting?  does it have anything to do with the console logs not being done in order?</p>