title: Node.js sleeps when not in use and takes a long period of time to respond initially
body: <p>I have deployed Node.js as a solution to return data from the database for a React single page application. The solution works like a charm and everything is good. However what I find happening (and cannot find a solution for) is that the Node.js seems to go to sleep when not utilized after a couple of minutes. Once React site is then 'activated' again - a page loaded that requires database access, the Node.js seems to wake up and return the data, this takes a minute or two to happen. It then functions as supposed to by serving further calls in a timely manner.</p>
  <p>Solutions online talk about Windows machine going to sleep but this is not the case here as I am connected to the machine at the time. Even if deployed locally on my development Windows 10 machine it is faster to stop and restart the Node server rather than to wait for it to respond.</p>
  <p>The development and production machines are Windows 10 based machines with 64Gigs of Ram utilizing Mysql database.</p>
  <p>I have not been able to find other solutions for this issue.</p>
  <p>Below is the App.js (or server.js) file for Node to launch the server and listen to the port 3002 for incoming requests:</p>
  <pre><code>const express = require(&quot;express&quot;);
  const ipfilter = require('express-ipfilter').IpFilter
  const bodyParser = require(&quot;body-parser&quot;);
  const cors = require('cors');
  const app = express();
  
  app.use(cors());
  
  // Whitelist the following IPs
  const ips = ['localhost']
  
  // parse requests of content-type: application/json
  app.use(bodyParser.json());
  
  // parse requests of content-type: application/x-www-form-urlencoded
  app.use(bodyParser.urlencoded({ extended: true }));
  
  // Create the server
  //app.use(ipfilter(ips, { mode: 'allow' }))
  
  // simple route
  app.get(&quot;/&quot;, (req, res) =&gt; {
    res.json({ message: &quot;Welcome to Server Application.&quot; });
  });
  
  require(&quot;./routes/customer.routes.js&quot;)(app);
  require(&quot;./routes/data.routes.js&quot;)(app);
  
  // set port, listen for requests
   app.listen(3002, () =&gt; {
    console.log(&quot;Server Connection Successful.&quot;);
    console.log(&quot;Server is running on port 3002.&quot;);
  }); 
  </code></pre>
  <p>I have also set up the connection with Database Pooling thinking that might be the solution as per below:</p>
  <pre><code>const connection  = mysql.createPool({
    connectionLimit : dbConfig.CONNECTIONLIMIT,
    host            : dbConfig.HOST,
    user            : dbConfig.USER,
    password        : dbConfig.PASSWORD,
    database        : dbConfig.DB,
    port            : dbConfig.PORT
  });
  </code></pre>
  <p>but the issue persists.</p>
  <p>Any assistance would be appreciated.</p>