Css failure in ejs template

css style is missing. It should be the path.
the access path is Request URL: http://localhost:3000/test.css
css and js are in the same directory, so there should be nothing wrong with writing the path this way.
the style can still come out when opened locally with html, but after running the js file locally, entering the URL to access the css style is gone.
I hope you Daniel can give us your advice. Thank you. Here is part of the code.

const express = require("express");
const consolidate = require("consolidate");

let server = express();

server.set("view engine" , "ejs");
server.set("views" , "./");
server.engine("html" , consolidate.ejs);

server.get("/" , (req , res) => {
  res.render("index.ejs" , {username:"eric"});
});
server.get("/about" , (req , res) => {
  res.render("about.ejs" , {username:"eric"});
});
server.get("/news" , (req , res) => {
  res.render("news.ejs" , {username:"eric"});
});
server.get("/home" , (req , res) => {
  res.render("home.ejs" , {username:"eric"});
});
server.get("/contact" , (req , res) => {
  res.render("contact.ejs" , {username:"eric"});
});

server.listen(3000);

-

<!DOCTYPE html>
<html>
<head>
    <title>nav</title>
    <link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
    <ul>
        <li><a href="/home"></a></li>
        <li><a href="/news"></a></li>
        <li><a href="/contact"></a></li>
        <li><a href="/about"></a></li>
    </ul>
</body>
</html>

should have nothing to do with the css code, so the css code is omitted.

Mar.05,2021

it is best to separate css files, for example, under the public folder in the same directory.
then use Express to host the static file: app.use (express.static (_ _ dirname+'public')); ).
the link to the corresponding visit is href= "/ public/test.css" .

Menu