title: Node events.js:174 throw er; // Unhandled 'error' event
body: <p>I get an error when requesting an API and it crashes on any win server. Can anybody help, please?</p>
  
  <p>This is part of my code:</p>
  
  <pre><code>app.get("/js/2806/api/products/getAllDrugs", (req, res) =&gt; {
  
  
      const connection = getDBConnection()
  
      const queryString = "SELECT * FROM tbl_drug";
  
      connection.query(queryString, (err, rows, fields) =&gt; {
  
          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) =&gt; {
              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
          })
      })
  
  
  });
  </code></pre>
  
  <blockquote>
    <p>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</p>
  </blockquote>