Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Express wont find css file

I cant get my index.html in express to show the styles.

This is my folder structure:

folder structure

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And then on server js I have this:

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

app.get('/', function(req, res){
  console.log('Listening on port ' + port)
  let isMobile = req.useragent.isMobile ? 'mobile' : 'desktop';
  console.log({isMobile})
  res.sendFile(path.resolve(__dirname + `/${isMobile}/index.html`));
});

And I just add the link tag on my html inside the head on the index.html like this:

  <link href="styles.css" rel="stylesheet" type="text/css">

The index I serve can be either inside the desktop or mobile folder
But it doesnt get the styles… any idea whats the issue?

Thanks.

>Solution :

server.js

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

index.html

<link href="/styles.css" rel="stylesheet" type="text/css">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading