title: How to include JS, CSS and other server-side utils to a HTML page in NodeJs using expressJs?
body: <p>I could not find any solutions that worked for me.</p>
  
  <p>I am trying to create a simple microservices architecture with Node.js instances. I do not use Dockerfile. The homepage microservices displays correctly the html with CSS, JS. The gateway microservice does <strong>not</strong> load the CSS, JS (the page looks broken).</p>
  
  <p><a href="https://i.stack.imgur.com/669Pg.png" rel="nofollow noreferrer">homepage html here</a></p>
  
  <p><a href="https://i.stack.imgur.com/nJ1jR.png" rel="nofollow noreferrer">gateway response html here</a></p>
  
  <p>At the moment I have 2 microservices:</p>
  
  <ol>
  <li>Express server that sends index.html as file. It loads correctly the page with assets (css, images, javascript). I have used <code>app.use(express.static('public'))</code>.</li>
  </ol>
  
  <p>homepage:</p>
  
  <pre><code>const express = require('express')
  const app     = express()
  var path      = require("path")
  
  app.use(express.static('public'))
  
  app.get('/', (req, res) =&gt; {
  
      res.sendFile(path.join(__dirname+'/public/index.html'));
  })
  
  app.listen(3001, () =&gt; console.log('Homepage listening on port 3001!'))
  </code></pre>
  
  <ol start="2">
  <li>Express server that receives requests and wants to deliver content to user. I am trying to create an API Gateway to filter traffic (on authentication for example) and write logs.</li>
  </ol>
  
  <p>gateway:</p>
  
  <pre><code>const express = require('express')
  const request = require('request-promise-native')
  const app = express()
  
  app.get('/', async (req, res) =&gt; {
      // Write logs in database
      const uri = "http://localhost:3001/"
      const result = await request(uri)
      res.send(result)
   })
  
   app.listen(3000, () =&gt; console.log('Public API Gateway listening on port 3000!'))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/3Rl7c.png" rel="nofollow noreferrer">Project structure with the 2 server files here</a></p>
  
  <p>Any solution is really appreciated.</p>
  
  <p>Thanks!</p>