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?

2
  • 1
    Check if this posts answers your question: stackoverflow.com/questions/48248832/… Commented Jun 24, 2020 at 7:34
  • 1
    Your right, after 3 hours I finally find incorrect in path Commented Jun 24, 2020 at 15:45

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

Thanks, but in my case was just broken path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.