Regarding Call back return value

14 views
Skip to first unread message

prem prem

unread,
Jan 4, 2018, 1:28:41 PM1/4/18
to nodejs
var result = [];
var  getInformationFromDB = function() {

mysql.connection.query('SELECT * FROM role', function(err, res, fields)
{
    if (err)  throw err;
     if(res.length){
    for(var i = 0; i<res.length; i++ ){     
                    result.push(res[i]);
        }
     }
   console.log("Inside npm");
   console.log(result);
   return result;
});
);

   console.log("Outside npm");
   console.log(result);
 console.log("Call Function");
   console.log(getInformationFromDB());

Output:
Outside npm
[]
Call Function
[]
Inside npm
[{Row1}, {Row2}]





Please suggest me assign value to outside variable??

Reply all
Reply to author
Forward
0 new messages