I am just starting with Express and express-ejs-layouts. I have a layout.ejs file that has the common parts of my web app. This works great for pages that are at http://localhost/path1/path2
, but I would also like to use this for the root index page of my app (i.e.: http://localhost/
The problem is the links for the CSS and JS files:
<link href="../../stylesheets/main.css" rel="stylesheet" type="text/css">
This doesn't work for http://localhost/
Should I break this out and add it to each view template with the correct pathing? How have people done this in the past?
You can use absolute URLs for static files (eg. href="/public/css/"
) to avoid this issue.
For Node.js/Express.js web applications, it's convenient to create a public
folder at the root, where you put all your static files.