I ran into the same issue and decided to give middleware like express.static() a go.
warning: when I declared express.static("public") I put it at the bottom of my app.js file and it didn't work for me. So I moved it up and it works.. here is the example
"use strict";
const express = require("express"),
app = express();
const layouts = require("express-ejs-layouts");
app.set("view engine", "ejs");
app.set("port", process.env.PORT || 3000);
app.use(
express.urlencoded({
extended: false
})
);
app.use(express.json());
app.use(layouts);
app.use(express.static("public"));
app.get("/", (req, res) => {
res.render("index");
});
app.listen( app.get("port"), () => {console.log(`Server running at http://localhost:${app.get("port")}`);
});
Then in public folder (where my css, js, images are), I put boostrap.css there
In layout.ejs I have html file and refer it as
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=1">
<title>School of business</title>
<link rel="stylesheet" href="/css/bootstrap.css"> <!-- BOOTSTRAP -->
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
.........
enter image description here