由于app.css文件不起作用,请帮助我检查代码中是否有错误。
const express = require("express");
const app = express();
const port = process.env.PORT || 4000
app.use(express.static("public"));
app.set('views', './views');
app.set('view engine', 'ejs');
app.get("/posts", function(req, res){
var posts = [
{title: "Once upon a time", author: "Richard"},
{title: "The Way", author: "Ikoro"},
{title: "I Love Critics", author: "Emmanuel"},
{title: "Adorable Bunny", author: "Christian"}
]
res.render("posts", {posts: posts});
});
这是我的公共目录,其中包含app.css文件
body {
background: #ffff00;
color: #800080;
}
答案 0 :(得分:0)
请westdabestdb查看视图/模板代码
<link rel="stylesheet" href="../public/app.css">
<h1>The Post Page</h1>
<!-- for Loop Syntax for Embedded JavaScript Templates -->
<% for(var i = 0; i < posts.length; i++){ %>
<li>
<%= posts[i].title %> - <strong><%= posts[i].author %></strong>
</li>
<% } %>
<!-- forEach Loop Syntax for Embedded JavaScript Templates -->
<% posts.forEach(function(post){ %>
<li>
<%= post.title %> - <strong><%= post.author %></strong>
</li>
<% }) %>