в том виде, в котором вы его используете, только внутри функции asyn c.
const sqlite3 = require("sqlite3").verbose();
let db = new sqlite3.Database("./indy.db");
async function getArr(sql) {
let arr;
arr = await new Promise(function(resolve, reject) {
let myRows = [];
db.all(sql, async function(err, rows) {
rows.forEach(row => myRows.push(row));
const error = false;
if (error) {
reject(new Error("Ooops, something broke!"));
} else {
resolve(myRows);
}
});
});
console.log("after await before return");
console.log(arr);
return arr;
}
console.log("before async call");
console.log();
console.log("after async call");
router.post("/query", async function(req, res) {
const body = req.body;
res.set("Content-Type", "text/plain");
res.send(await getArr(req.body.sql));
});