Node.JS function to return the value of a async callback function
<p>In Node.JS, I have a function to connect with a MySQL database, get a bunch of rows, and then return them as an array. My problem is with <code>asynchronous</code> code, I am using the <code>async</code> Node.JS module.</p>

<p>This is my function so far:</p>

<pre><code>var async = require("async")
function get_all_channels_by_order(){
    async.waterfall([
        function(callback){
            mysql_connection.connect()
            mysql_connection.query("SELECT * FROM channels ORDER BY listorder ASC", function(err, result){
                callback(null, result)
            })
        }
    ], function(err, result){
        mysql_connection.end()
        return result
    })
    //return ?? somehow, return the value from the MySQL query?
}
console.log(get_all_channels_by_order())
</code></pre>

<p>The problem appears when the line to call for the function already checks for the return value even though it wasn't sent yet.</p>

<p>How can this be done? Is it even possible? I realize I can just not use this function and manually do the query when ever I need it but that would end up completely not organized and messy.</p>

<p>I previously asked this question '<a href="https://stackoverflow.com/questions/36656716/change-a-variable-from-outside-its-scope/36656825#36656825">Change a variable from outside it&#39;s scope</a>' which was marked as a duplicate of '<a href="https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron">Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference</a>', that question talks about asynchronous code, not how to have a function return a value from it and I can not figure out how.</p>