0

I am creating a blog application using nodejs and express with ejs. everything is working fine with a single URL ( means http://localhost/ or http://localhost/anything ), but when I am trying to access a page http://localhost/blog/create in this page external stylesheet or javascript not working, it's loading as http://localhost/blog/css/style.css (it should be http://localhost/css/style.css).

I am using middleware static to load css and js from public directory

app.use(express.static(__dirname + '/public'));

header and footer are loading using <%- include('./partials/header') %>

Directory Structure:

View Files : views
header & footer : views/Partials
css and js : public
kedar sedai
  • 1,687
  • 3
  • 16
  • 25
Jasir
  • 57
  • 6

1 Answers1

1

your style sheet should use '/css/style.css' instead of 'css/style.css'

There are some good explanations here Absolute vs relative URLs

Someone Special
  • 12,479
  • 7
  • 45
  • 76