I am working on an Node JS with Express API. After getting data from MySQL database, the response data must be pass in the variable outside the function.
Here is the primary function:
function get_orders(callback) {
dbConnection.query(
"CAll orders.getOrders()",
async (err, rows, fields) => {
if (!err) {
if (rows.length !== 0) {
return await callback(rows[0][0]);
}
} else {
throw err;
}
}
);
}
Here were I call the primary function:
function call_orders(req, res) {
let data;
get_orders(async (result) => {
data = await result;
});
}
I was assuming that data variable will have the values from get_orders() function but unfortunately its shows 'undefined'.