title: Express.js route almost everything to one request
body: <p>I want to map all the requests that don't point to static files to my <code>index.html</code> and let javascript do the routing. But if I use the rules below all my requests (including the scripts and styles) hit the <code>*</code> rule.</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>const express = require("express");
  
  var app = express();
  
  app.get("*", function (request, response) {
      response.sendFile(path.join(__dirname, "/index.html"));
  });
  
  app.use("/scripts/*", express.static("scripts"));
  app.use("/styles/*", express.static("styles"));
  app.use("/views/*", express.static("views"));
  
  var port = process.env.PORT || 3000;
  
  app.listen(port, function () {
      console.log("Server is running, port: " + port);
  });</code></pre>
  </div>
  </div>
  </p>
  <p>I've also tried the reverse order.</p>
  <p>Just to clarify here are some examples of what the expected behavior is:</p>
  <ul>
  <li><code>/scripts/index.js</code> =&gt; <code>/scripts/index.js</code></li>
  <li><code>/views/app.html</code> =&gt; <code>/views/app.html</code></li>
  <li><code>/anything/here</code> =&gt; <code>/index.html</code></li>
  <li><code>/</code> =&gt; <code>/index.html</code></li>
  <li><code>/a/lot/of/stuff</code> =&gt; <code>/index.html</code></li>
  </ul>
  <p>I want to upload this to heroku and I don't want to use that many free credits. So I want to have all the routing and stuff on the JS to save up on computation on the server.</p>