Strider2342
Strider2342

Reputation: 63

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?

Upvotes: 0

Views: 266

Answers (2)

Trkulja Igor
Trkulja Igor

Reputation: 1

Try this:

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

Upvotes: 0

grimurd
grimurd

Reputation: 2850

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

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

Upvotes: 3

Related Questions