title: npm-mysql crashes overnight
body: <p><em><strong>The class:</strong></em></p>
  <pre class="lang-js prettyprint-override"><code>const mysql = require('mysql');
  module.exports = function () {
  
    this.connection = mysql.createConnection({
      host     : 'localhost',
      user     : 'USER',
      password : 'PASSWORD',
      database : 'DATABASE',
      multipleStatements: true
    });
    
    this.query = (sql, args) =&gt; {
      return new Promise( ( resolve, reject ) =&gt; {
        this.connection.query( sql, args, ( err, rows ) =&gt; {
          if ( err )
            return reject( err );
          resolve( rows );
        });
      });
    };
  
    this.close = () =&gt; {
      return async () =&gt; {
        try {
          this.connection.end(err =&gt; {
            if (err) throw err;
            return;
          });
        } catch(e) {
          return e;
        }
      }
    };
  };
  </code></pre>
  <p><em><strong>In index i call it like this:</strong></em></p>
  <pre class="lang-js prettyprint-override"><code>const Database = require('./server/modules/mysql'),
        connection = new Database();
  </code></pre>
  <p><em><strong>The problem:</strong></em>
  Overnight mysql crashes:</p>
  <pre class="lang-js prettyprint-override"><code>[nodemon] starting `node index.js`
  listening on port 420
  events.js:292
        throw er; // Unhandled 'error' event
        ^
  
  Error: Connection lost: The server closed the connection.
      at Protocol.end (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\protocol\Protocol.js:112:13)
      at Socket.&lt;anonymous&gt; (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\Connection.js:94:28)
      at Socket.&lt;anonymous&gt; (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\Connection.js:526:10)
      at Socket.emit (events.js:327:22)
      at endReadableNT (_stream_readable.js:1221:12)
      at processTicksAndRejections (internal/process/task_queues.js:84:21)
  Emitted 'error' event on Connection instance at:
      at Connection._handleProtocolError (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\Connection.js:423:8)
      at Protocol.emit (events.js:315:20)
      at Protocol._delegateError (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\protocol\Protocol.js:398:10)
      at Protocol.end (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\protocol\Protocol.js:116:8)
      at Socket.&lt;anonymous&gt; (C:\Users\fedesc\Sites\borsalino\node_modules\mysql\lib\Connection.js:94:28)
      [... lines matching original stack trace ...]
      at processTicksAndRejections (internal/process/task_queues.js:84:21) {
    fatal: true,
    code: 'PROTOCOL_CONNECTION_LOST'
  }
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  <p>I'm using Nodemon and a simple restart to the application solves the issue until the next morning (or next long period of not coding.)</p>
  <p>I'm not really using <code>close()</code> anywhere or after anything since in the docs it says it's not needed, just <code>query()</code>.
  but clearly i get a <code>timeout</code> somewhere somehow, like i should deal with the opening and closing of connection.</p>
  <ol>
  <li>Do i need to close connections after making queries in my app?</li>
  <li>Is there a way to set the timeout limit or dealing with him?</li>
  <li>Am i just setting it up wrong or using wrong/outdated tool?</li>
  </ol>
  <p>Thanks.</p>