I'm making a web application using node.js, express and mysql. I need to change this variable num with the data that I get from the SQL query. Do you know how I can change this variable inside a callback? Or how else can I get this data from this query. I have seen many questions about a similar problem, but none of them helped me :(
router.get('/:filters?', function(req, res, next) {
let num;
if (!req.params.filters) {
connect.query('SELECT COUNT(*) FROM STUDENTS', (err, res) => {
num = res[0];
});
console.log(num); // => undefined
//...
}
});