简体   繁体   中英

ExpressJS error: MIME type ('text/html') is not a supported stylesheet MIME type

When launching my NodeJS server and typing localhost:8080 , I get the previously mentioned error as it loads the page. Below is my head section in my index.html file, I'm not sure why this occurs, my index.html is in the same directory as script.js and style.css .

<head>
  <meta charset="utf-8">
  <title>Express & Node Test</title>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <script src="script.js" type="text/javascript"></script>
</head>

Using the following snippet from my app.js file for ExpressJS routing.

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

I've had no success searching my problem so I have resorted to asking on StackOverflow, any help would be greatly appreciated.

You can set your code like this in order to serve files from the current directory, Instead of path.join you can use:

      app.get('/', (req, res) => {
res.sendFile(__dirname + "/index.html"); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM