title: Node.js mysql read ECONNRESET
body: <p>After searching for long time regarding this error and not really be able to figure out how to handle this error in my project. I need some help from you :).</p>
  <p>I've got the problem, that my Screen with my Node-APP will give me a error after some hours (I don't know after how many hours but my feeling says me it isn't always the same time)</p>
  <p>I will give you my error below. Does anyone know how to fix this? I already tried with an interval of select everything from one short table, to reset the connection to database, so the connection will not be closed, because there will be always (every 30 Minutes) a short call to the Database.</p>
  <p>Also after I get the error and restart the app everything works fine. I saw its a idle-time problem, but I did not find any way to solve this problem for me.
  This is how I create the connection to my database.</p>
  <pre><code>var con = mysql.createConnection({
     host: process.env.DATABASE_HOST,
     user: process.env.DATABASE_USER,
     password: process.env.DATABASE_PASSWORD,
     database: process.env.DATABASE });
  
  
    con.connect(function(err) {
     if (err) throw err;
     console.log(&quot;Connected to Database!&quot;);
   });
  </code></pre>
  <p>Thank you very much in advance!</p>
  <p>The best regards</p>
  <p>The error:</p>
  <pre><code>node:events:371
        throw er; // Unhandled 'error' event
        ^
  
  Error: read ECONNRESET
  
      at TCP.onStreamRead (node:internal/stream_base_commons:211:20)
  Emitted 'error' event on Connection instance at:
      at Connection._handleProtocolError (/var/www/xxx/xxx/node_modules/mysql/lib/Connection.js:423:8)
      at Protocol.emit (node:events:394:28)
      at Protocol._delegateError (/var/www/xxx/xxx/node_modules/mysql/lib/protocol/Protocol.js:398:10)
      at Protocol.handleNetworkError (/var/www/xxx/xxx/node_modules/mysql/lib/protocol/Protocol.js:371:10)
      at Connection._handleNetworkError (/var/www/xxx/xxx/node_modules/mysql/lib/Connection.js:418:18)
      at Socket.emit (node:events:394:28)
      at emitErrorNT (node:internal/streams/destroy:157:8)
      at emitErrorCloseNT (node:internal/streams/destroy:122:3)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -104,
    code: 'ECONNRESET',
    syscall: 'read',
    fatal: true
  }
  </code></pre>
  <p>And again THANK YOU!!! :)</p>