title: Data in global variable not getting updated
body: <pre><code>exports.index = function(req, res) {
       var names = [];
       connection.query('SELECT * from shares', function(err, rows) {
          if (err)
            console.log('error in execution...');
          else {
            names = []
            for ( var i in rows) {
              names.push(rows[i].title);
            }
          }
       });
      //var names = heroes.map(function(p) { return p.name; });
       console.log('names : ' + names);
      res.render('index', { heroes: names });
  };
  </code></pre>
  
  <p>In the above code, I want to print the value of name at the end of the function. Its printing nothing. Can somebody tell me how to fix ? </p>