node.js mysql insert id - how do I expose the insert id outside of the insert query?
<p>Let's say I have a list of values in a json format (or any format) I need to insert into a mysql table.   After the insert, I need the result.insertId exposed outside of the mysql.query call.  Is there a way to do that?  (please, don't ask me why I need this: I know how to work around this. I just need to know if this scenario is possible).  Ideally, the description and insert Id of each array item should print to the screen. Instead, I get an empty array.  Yes, I know that putting console.log <em>inside</em> of the callback will achieve this.  That's not the answer I need.  Is it possible to expose the insert Id outside of the callback?</p>

<pre><code>var todos = require('./todos.json');
var mysql = require('mysql');

var mysql_pool = mysql.createPool({
  host : 'localhost',
  user : 'myuser',
  password : 'mypwd',
  database : 'mydb'});

var todoArray = [];

todos.forEach(function(todo) {
   mysql_pool.query("INSERT INTO todos(description) VALUES(?)", todo.description, function(err, result){
        if (err) {
            console.log(" Unable to insert: " + err);
            throw err;
            }
        todoArray.push({description: todo.description, desc_id: result.insertId});
    });
});

console.log(todoArray);
</code></pre>