请求API时出现错误,它在任何Win服务器上崩溃。有人可以帮忙吗?
这是我的代码的一部分:
app.get("/js/2806/api/products/getAllDrugs", (req, res) => {
const connection = getDBConnection()
const queryString = "SELECT * FROM tbl_drug";
connection.query(queryString, (err, rows, fields) => {
if (err) {
console.log("Failed to query for drugs: " + err);
// res.sendStatus(500);
res.json({
ErrorDetail: {
code: -1,
msg: err.code
}
});
res.end();
return
}
const drugs = rows.map((row) => {
return {
id: row.id,
storeId: row.drugStoreId,
drugName: row.drugName,
description: row.drugDsc,
drugUsing: row.drugUsing,
drugDoseId: row.drugDoseId,
categoryId: row.categoryId
};
})
res.json({
ErrorDetail: {
code: 0
},
Response: drugs
})
})
});
错误:连接丢失:服务器关闭了连接。在Socket的Protocol.end(C:\ Users \ Administrator \ AppData \ Local \ CaptainCure \ n s \ mysql \ lib \ protocol \ Protocol.js:112:13)中。 (C:\ Users \ Administrator \ AppData \ Local \ Captain odules \ mysql \ lib \ Connection.js:97:28)在套接字。 (C:\ Users \ Administrator \ AppData \ Local \ Captain odules \ mysql \ lib \ Connection.js:502:10)在Socket.emit(events.js:194:15)在endReadableNT(_stream_read.js:1125:12) )在process._tickCallback(内部/进程/next_tick.js:63:19)在Connection._handleProtocolError(C:\ Users \ Administrator \ AppData \ ainCure \ node_modules \ mysql \ lib \ Connection.js :425:8)at Protocol.emit(events.js:189:13)at Protocol._delegateError(C:\ Users \ Administrator \ AppData \ Local \ Ca node_modules \ mysql \ lib \ protocol \ Protocol.js:390:10 ),位于Socket的Protocol.end(C:\ Users \ Administrator \ AppData \ Local \ CaptainCure \ ns \ mysql \ lib \ protocol \ Protocol.js:116:8)。 (C:\ Users \ Administrator \ AppData \ Local \ Captain odules \ mysql \ lib \ Connection.js:97:28)I-与原始堆栈跟踪匹配的行...] at process._tickCallback Cinternal / process / next_tick.js: 63:19> [nodemon I-等待进入(nodemon],位于'node app.js -erver正在端口上运行:3000 ode events.js:174 throw er; //未处理的'error'事件正在(nodemon]开始'node app.js'-erver在端口3000上运行
答案 0 :(得分:0)
由于服务器已经在运行,因此我们必须重新启动。 并且如果您同时使用iterm和终端机,则需要确保您只使用了另一个,而必须关闭。