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??