【发布时间】:2021-09-26 12:20:10
【问题描述】:
我刚刚开始使用 ExpressJS。所以这里 console.log 有效,所以如果我打电话,我会在打印的终端结果数据集中看到它。但是,它不会将其作为响应返回。我做了 console.log 并返回,但仍然没有得到响应的数据..
index.js
...
app.get("/", async (req, res) => {
let data = await queries();
res.json(data);
});
...
也试过了
...
app.get("/", (req, res) => {
res.json(queries());
});
...
queries.js
function main(sql) {
return pool.getConnection((err, connection) => {
if (err) throw err;
return connection.query(sql, (errt, rows) => {
connection.release(); // return the connection to pool
if (errt) throw err;
console.log(rows);
return rows;
});
});
}
function queries() {
let Q = "SELECT * FROM `items`";
return main(Q);
}
【问题讨论】:
标签: javascript mysql node.js api express