简体   繁体   中英

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

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

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\\ns\\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\\ns\\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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM