title: Server NodeJs crashes in idle time and how do I fix it?
body: <p>My server api is on alwayse alwaysdata.
  After x time the server crash.</p>
  
  <pre><code>events.js:183
    throw er;
   // Unhandled 'error' eventError: Connection lost: The server closed the connection.
  at Protocol.end (/home/ec2-user/node_modules/mysql/lib/protocol/Protocol.js:112:13)
  at Socket.&lt;anonymous&gt; (/home/ec2-user/node_modules/mysql/lib/Connection.js:97:28)
  at Socket.&lt;anonymous&gt; (/home/ec2-user/node_modules/mysql/lib/Connection.js:502:10)
  at emitNone (events.js:111:20)
  at Socket.emit (events.js:208:7)
  at endReadableNT (_stream_readable.js:1064:12)
  at _combinedTickCallback (internal/process/next_tick.js:139:11)
  at process._tickCallback (internal/process/next_tick.js:181:9)
  </code></pre>
  
  <p>I'm looking at whether this could not be related to a mysql error. but pre-existing posts do not help me. I think the server mysql cut the connection I do not know why. 
  here I establish the connection:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let con = mysql.createConnection({
              host: "alwaysdata.net",
              user: "user",
              password: "",
              database: "database"
          });
  
          try {
              con.query(check, (err, customer) =&gt; {
              if (err){
                  console.log("%s Error on check query",Date());
                  throw err;
              }</code></pre>
  </div>
  </div>
  </p>