Home > OS >  (Node Express)Refused to apply style because its MIME type ('text/html') is not a supporte
(Node Express)Refused to apply style because its MIME type ('text/html') is not a supporte

Time:10-19

Refused to apply style because of MIME type. I can't serve css for my html page via Express. I've tried everything but I feel like I am overlooking something simple and just would like some fresh eyes to analyze my code to see where I am messing up at.

server.js

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

 app.get('/', (req, res)=> {
     res.sendFile(path.join(__dirname, 'index.html'))
 })

The index.html runs just fine but without any css styling.

My html css link is:

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

and my file structure is

                     >backend
                      index.html
                      server.js

                     >public
                       styles.css

CodePudding user response:

Your /public does not have a forward slash at the end, you can try it including in href your HTML.

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

Also, check your static public folder is actually set up correctly with provided path and that can access your styles.css file.

  • Related