Search code examples
node.jsexpressstaticstylesheet

Style sheet in express static folder


I have set the static folder like this:

app.use(express.static(path.join(__dirname, '/public')));

And referenced the style sheet (which can be found in "public/stylesheets") like this:

<link rel="stylesheet" href="stylesheets/style.css">

And it works fine on localhost:3500/ and on localhost:3500/items, but when i go on localhost:3500/items/get, it searches for the style sheet in "items/stylesheets". What should I do, so the "public" library stays the same wherever I am?


Solution

  • You're missing a forward slash so it always searches relative to the root of your website

    <link rel="stylesheet" href="/stylesheets/style.css">