我知道这似乎是重复但我已经看了其他答案,但它们对我不起作用。这是我的代码:
的NodeJS:
var express = require("express"),
app = express(),
mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/e_c");
app.use(express.static(__dirname+"public"));
app.use(express.static(__dirname+"partials"));
var blogSchema = new mongoose.Schema({
title: String,
author: String,
pictureForTitle: String,
content: String
});
var blog = mongoose.model("blog",blogSchema);
app.set("view engine","ejs");
app.get("/",function(req,res){
res.render("home");
});
app.listen(process.env.PORT,process.env.IP);
Head.ejs:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/public/css/styles.css">
</head>
<body>
<nav id="navBar">
<div id="aboutSite">
<p>About This Site</p>
<div id="aSDropContent">
<p>About The Author Of This Site</p>
<p>Why The Author Created This</p>
</div>
</div>
</nav>
我已经尝试过express.static,你可以看到。但它不起作用。我甚至尝试过复制/查看以前的项目。
非常感谢, Josh C。
答案 0 :(得分:0)
我遇到了同样的问题并通过将“ public ”替换为“ / public ”来解决此问题
app.use(express.static(__dirname+"/public"));
和
href="/css/styles.css"