Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Issue with express static middleware and subdirectory

I have this folder as my website structure

-views
  -index
  -post
-public
  -css
  -js
  -images
-app.js

But a post link can be:

mywebsite.com/posts/a-link-example

So, when I use express static middleware like this:

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

it only works in pages without a "subdirectory" like

example.com/home
example.com/contact

but not on

example.com/posts/post-name

I can use of course:

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

but is there a better way to do it?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Don't use relative paths to point to static resources (like scripts and stylesheets), use absolute paths:

<link rel="stylesheet" href="/css/style.css">
about 4 years ago · Santiago Trujillo Report

0

You can change static asset links from:

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

to:

<link rel="stylesheet" href="/css/style.css">
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!