1

I add static CSS,

and this file exists in source code of the page,

but CSS not applied...

In console wrote "blocking CSS because MIMO type does not define correctly"

In link tag type='text/css' exist.

Ask is how I can define 'Content-type' in express automatically?

Hamada
  • 1,836
  • 3
  • 13
  • 27

2 Answers2

1

You can create public folder and add all the client side files.

In your server side you must use it :

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

with path module :

npm install path
0

I had the same issue yesterday and solved it. So first node uses folder path to get files. That means that if you're at http://localhost:3000/ you are at the root of your directory. also you can access your stylesheet via http://localhost:3000/public/css/style.css.

But, you can modify the path using routes and express.static().

You may have an url which is http://localhost:3000/user/index. So he is seeking for the css file such as http://localhost:3000/user/public/css/style.css which does not exist.

the solution might be to use different route files like this :

app.use('/', indexRouter);
app.use('/users', usersRouter);
Thomas Ung
  • 154
  • 13