title: Node.JS + Express show loading page while getting real page content
body: <p>Basically, I have a system which goes to a Database, fetches some information, then goes to some other sites, and fetches some information. This takes about 3 seconds. What I'd like to do, is display a <code>This Page Is Loading</code> page while the server is fetching the rest of the data, and once all the data is fetched, I'd like the server to send the destination page.</p>
  
  <pre class="lang-js prettyprint-override"><code>const express = require('express');
  const app = express();
  app.set('view engine','ejs')
  app.use(express.static('public'));
  app.set('views', '/app/public/')
  app.get('/', async(req, res) =&gt;{
      //Need to send `This Page Is Loading` here.
      //Contact DB (takes 3 seconds)
      res.send("home/index")//Send the final page.
  })
  
  
  
  </code></pre>
  
  <p>I am using Node.JS + Express + Ejs, so we might be able to pull the DB info in the ejs file and display loading screen. Not too sure thou..</p>
  
  <p>An idea that I've got.</p>
  
  <pre class="lang-js prettyprint-override"><code>const express = require('express');
  const app = express();
  app.set('view engine','ejs')
  app.use(express.static('public'));
  app.set('views', '/app/public/')
  function getdbinfo(name){
      //getinfo
      return info
  }
  app.get('/', async(req, res) =&gt;{
      res.send("home/index",{req,getdbinfo})//Send a page with get info function.
  })
  
  
  </code></pre>
  
  <p>And on the ejs page, we would need to display a loading page and in the background make the requests.</p>