title: Node.js - Express: Weird local paths
body: <p>This is so weird how my local paths work. Like for example here is what my hierarchy looks like:</p>
  <blockquote>
  <p>public &gt; css &gt; bootstrap.css</p>
  <p>public &gt; js &gt; bootstrap.js</p>
  <p>templates &gt; layout &gt; page.ejs (default template for any page)</p>
  <p>templates &gt; index.ejs and other .ejs templates</p>
  </blockquote>
  <p>So inside of my page.ejs are my styling and scripting links:</p>
  <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;css/bootstrap.css&quot;/&gt;
  
  &lt;script src=&quot;js/jquery.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;js/bootstrap.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>And it works for my index.js for some reason. Whenever I go on to the website and I check the source, click on the links, all found and good. Whenever the same happens with my example.ejs file - these links are not found since it is being called from the /players/ directory in the source.</p>
  <p>So for example a call for those files from the '/' page looks like:</p>
  <pre><code>GET /css/bootstrap.css 304 3.155 ms - -
  GET /js/jquery.js 304 3.748 ms - -
  GET /js/bootstrap.js 304 3.714 ms - -
  </code></pre>
  <p>But the call for the same file from the same template from /players/ is called like this:</p>
  <pre><code>GET /players/css/bootstrap.css 404 1.436 ms - 38
  GET /players/js/jquery.js 404 1.197 ms - 33
  GET /players/js/bootstrap.js 404 1.151 ms - 36
  </code></pre>
  <p>And obviously they are with tag 404 since they were not found. So my question is:</p>
  <blockquote>
  <p>How do I work with all of my paths?</p>
  </blockquote>
  <p>I have tried absolute paths to those files - still not found. I have tried of think of some kind of dynamic script but I'm still not sure how it works.</p>
  <p>For some reason it adds its own path to the files and not uses the path of the template... Ugh, I don't even know how to explain it but I think you get the idea. I think the &quot;public&quot; directory is tied to the routes so that's why I don't need to include it to the files that are requested from the index page but what about any other files?</p>
  <p>Thank you and sorry for a lame question!</p>