0

I meet some problems with my node code. So the thing is I want to create a local server on port 3000. After I link my html code which is

app.get("/",(req,res,next)=> {
    res.sendfile(path.join(__dirname+'/src'+'/index.html'));
})

my chrome browser showed that :

Refused to apply style from 'http://localhost:3000/app.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Plus, my CSS is not working. Here is the CSS tag in my HTML

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

Anyone knows how to fix it? Thank you so much! 😊

1 Answer 1

1

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express

var express = require('express');
var app = express();

app.use(express.static('public'));

Read more about Serving static files in Express

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! Problem Solved!

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.