Array.push works fine if I console.log inside the loop. However, the array is empty outside the loop. Any thoughts on why?
It was working fine before, I changed something and the array has been empty ever since even if I undo the changes.
this.router.post('/hello', async(req, res) =>{
            console.log("We are in");
            var connection = mysql.createConnection({
                host     : 'host12',
                user     : 'root12',
                password : 'password12',
                database : 'db12',
            });
            var count = req.body.count;
            console.log("the count:" +count);
            while(i<count) {
                connection.query('INSERT INTO x (DateM) VALUES ("2021-10-10")', function (error, result, field) {
                    if (error) {
                        console.log("Insert Error: " + error);
                    } else {
                        insertID = result.insertId;
                        connection.query("UPDATE table SET mitID =" +insertID "where ID=" + insertID, function (errors, results, fields) {
                            if (errors) {
                                console.log("Update Errors: " + errors);
                            } else {
                                console.log(results);
                                var cId = Q + insertID;
                                idList.push(cId);
                            }
                        });
                    }
                });
                i++;
            }
            console.log(idList);
            res.json(idList);
        });
Thanks!
 
     
    