title: Node Express Server : How to serve HTML file properly (scripts and css included) ? (csp, relative path and thing like that)
body: <p>(I know this question have been asked many times in many form, but I tried a lot of solution and none work the way it should.. So maybe a solution adapted to my work would help me understand.)</p>
  
  <p>Here is the <a href="https://i.stack.imgur.com/6SzZL.jpg" rel="nofollow noreferrer">structure of my project</a>.</p>
  
  <p>Here is the index.html :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;link rel="stylesheet" href="./../node_modules/bootstrap/dist/css/bootstrap.min.css"&gt;
  
      &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;nav class="navbar navbar-default "&gt;
          &lt;div class="container-fluid"&gt;
              &lt;div class="navbar-header"&gt;
                  &lt;a class="navbar-brand" href="#"&gt;Brand&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/nav&gt;
  
      &lt;script src="../node_modules//bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script src="./../node_modules/jquery/dist/jquery.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is the server/app.js. I let the res.sendFile(); empty on purpose.</p>
  
  <pre><code>//export used
  var express = require('express'),
      url = require("url"),  
      path = require("path"),  
      fs = require("fs");
  
  const _port = 3000
  var app = express();
  
  app.get('/', function(req, res){
      res.sendFile();
  });
  
  app.listen(_port, function() { console.log('listening port '+_port+"\n__dirname : "+__dirname)});
  </code></pre>
  
  <p>The purpose of the server for now is just to send the index.html, that is one level up in the public folder. when a request in made to '/'. and I CAN'T DO IIIITT,
  for several reason:<br>
  -I tried to use helmet to workaround Content Security Policy.<br>
  -I tried to use the static middleware to do stuff..<br>
  -I tried to use the path.join / resolve  </p>
  
  <p>So is there anyone who can explain somehow how to send this public/index.html file with the bootstrap scripts/css working ? </p>
  
  <p>Have a nice day </p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>Here is the new app.js, it render the index.html thanks to the express.static but bootstrap css/scripts are not rendered : </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>//export used
  var express = require('express'),
      url = require("url"),  
      path = require("path"),  
      fs = require("fs");
  
  const _port = 3000
  var app = express();
  
  
  
  app.use(express.static(path.join(__dirname, '/..', 'public')));
  
  app.get('/', function(req, res){
      res.sendFile('../public/index.html',{root: __dirname});
  });
  app.listen(_port, function() { console.log('listening port '+_port+"\n__dirname : "+__dirname)});</code></pre>
  </div>
  </div>
  </p>