Skip to content
Advertisement

Refused to apply style from ‘http://localhost:2000/cssFile/style.css’ because its MIME type (‘text/html’)

I am currently trying to add my style.css file to home.ejs file render by express.js

But I keep receiving the following error

JavaScript

My file structure is like

JavaScript

This is my express code

JavaScript

My home.ejs:

JavaScript

I have been trying for another solution, but I just can’t solve mine.

Advertisement

Answer

My file structure is like

JavaScript

This is my express code

JavaScript

In this JavaScript code, you’re telling express.static that you’re trying to service static files from a directory called “public”, which doesn’t exist. If you look in the “Network” panel in your browser, you’ll probably see that you’re getting served a 404 page, or sometimes a different HTML file.

Try changing your file structure to this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement