(JS) Starting server loads HTML but not css or jpg

  Kiến thức lập trình

This is server.js which I am starting in cmd using node server.js:

const express = require("express");
const path = require("path");
const app = express();
const port = 3000;

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

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

app.listen(port);

This is a section of index.html where I join it with css and create one image:

<!DOCTYPE html>
<html>
    <head>
        <title>Dućan s hranom</title>
        <link rel="stylesheet" href="/public/styles/stil.css">
    </head>

    <body>
        <div id="div1">
            <img src="/public/images/logo.jpg" id="logo">
            <span id="kat">Voće</span>
            <div id="div2">

This is part of my error msg:

Refused to apply style from ‘http://localhost:3000/public/styles/stil.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.
localhost/:10

   GET http://localhost:3000/public/images/logo.jpg 404 (Not Found)

localhost/:18

   GET http://localhost:3000/data/data.js net::ERR_ABORTED 404 (Not Found)

localhost/:1 Refused to execute script from ‘http://localhost:3000/data/data.js’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.
localhost/:91

This is what my directory looks like, but instead of ejs i use html for now

Started server with node server.js, and I was expecting it to open my html file and load css and images.

New contributor

Tomislav Kušek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT