Synchronous MySQL query with NodeJS and KnexJS
<p>I'm new with NodeJs so I'm stuck with its async behavior, in particular with queries to a MySQL database based on the KnexJS module</p>

<p>Here is the function with the queries:</p>

<pre><code>var getNotes = function(owner) {
        if(owner !== undefined) {
            knex.table('tblnotes').where('public',1).orWhere({ownerName : owner}).select('noteId').then(function(result) {
                console.log(result);
                return result;
            });
        }
        else {
            knex.table('tblnotes').where('public',1).select('noteId').then(function(result) {
                console.log(result);
                return result;
            });
        }
}
</code></pre>

<p>But when I use it</p>

<pre><code>var query = getNotes(user.username);
console.log("authenticated");
console.log(query);
console.log("--------------------------------------");
return res.render('authindex.ejs', {title : "Index", user : user,data : query});
</code></pre>

<p>and I log the result I have:</p>

<pre><code>authenticated
undefined
--------------------------------------
[ { noteId: 1 } ]
</code></pre>