javascript 节点 events.js:174 throw er; // 未处理的“错误”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55436085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:32:50  来源:igfitidea点击:

Node events.js:174 throw er; // Unhandled 'error' event

javascriptnode.js

提问by Alireza Jaba

I get an error when requesting an API and it crashes on any win server. Can anybody help, please?

请求 API 时出现错误,并且在任何 win 服务器上崩溃。有人可以帮忙吗?

This is part of my code:

这是我的代码的一部分:

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
        })
    })


});

Error: Connection lost: The server closed the connection. at Protocol.end (C:\Users\Administrator\AppData\Local\CaptainCure\n s\mysql\lib\protocol\Protocol.js:112:13) at Socket. (C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:97:28) at Socket. (C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:502:10) at Socket.emit (events.js:194:15) at endReadableNT (_stream_readable.js:1125:12) at process._tickCallback (internal/process/next_tick.js:63:19) Emitted 'error' event at: at 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) at Protocol.end (C:\Users\Administrator\AppData\Local\CaptainCure\n s\mysql\lib\protocol\Protocol.js:116:8) at Socket. (C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:97:28) I— lines matching original stack trace ...] at process._tickCallback Cinternal/process/next_tick.js:63:19> [nodemon I - wait in is (nodemon] si ing 'node app.js -erver is running on port: 3000 ode events.js:174 throw er; // Unhandled 'error' event is (nodemon] starting 'node app.js' -erver is running on port: 3000

错误:连接丢失:服务器关闭了连接。在 Protocol.end (C:\Users\Administrator\AppData\Local\CaptainCure\ns\mysql\lib\protocol\Protocol.js:112:13) 在 Socket。(C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:97:28) 在 Socket。(C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:502:10) 在 Socket.emit (events.js:194:15) at endReadableNT (_stream_readable.js:1125:12) ) 在 process._tickCallback (internal/process/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 ) 在 Protocol.end (C: \Users\Administrator\AppData\Local\CaptainCure\ns\mysql\lib\protocol\Protocol.js:116:8) 在 Socket。(C:\Users\Administrator\AppData\Local\Captain odules\mysql\lib\Connection.js:97:28) I— 匹配原始堆栈跟踪的行 ...] 在 process._tickCallback Cinternal/process/next_tick.js: 63:19> [nodemon I - wait in is (nodemon] si ing 'node app.js -erver is running on port: 3000 ode events.js:174 throw er; // 未处理的'错误'事件是 (nodemon] 开始'node app.js' -erver 在端口上运行:3000 js -erver 正在端口上运行:3000 ode events.js:174 throw er; // 未处理的 'error' 事件是 (nodemon] 启动 'node app.js' -erver is running on port: 3000 js -erver 正在端口上运行:3000 ode events.js:174 throw er; // 未处理的 'error' 事件是 (nodemon] 启动 'node app.js' -erver is running on port: 3000

回答by Gaurank Sharma

Because of the server is already running on back so we do have to restart. and if your using both iterm and the terminal so you need to make sure that the you use only one other one you have to close.

由于服务器已经在后面运行所以我们必须重新启动。如果您同时使用 iterm 和终端,那么您需要确保您只使用另一个,您必须关闭。