Node.js/MySQL: Printing actual query in error log in Node.js
<p>I have some Node.js code that tries to update a database in something like the following:</p>

<pre><code>connection.query(command, function(err,rows) {
        if (err){
            console.log(command);
            console.log("ERROR");
            console.log(err);
            return;
        }
        console.log("good");
    });
</code></pre>

<p>The above is run repeatedly for different values of "command", thus generating different queries to the database. The problem is that when there is an error, the wrong query gets printed in the <code>console.log(command)</code>. This is because the time the query is added to the queue, and the time the query is actually executed are not the same, so the value of "command" at each of these times isn't the same. Is there a way around this?</p>

<p>Note: <code>console.log(err)</code> prints the error itself, and also part of the query, but it only prints the line where the error occurred. I want to print the whole query.</p>