【问题标题】:CSS reference failure in express: why and how to fix?Express 中的 CSS 引用失败:为什么以及如何解决?
【发布时间】:2018-08-26 16:27:57
【问题描述】:

这是我拥有的一个简单的快递服务器:

// a small demo to exercise
var express = require("express");
var app = express();
var bodyparser = require("body-parser");

app.use("/public/", express.static("./public/"));
app.use("/node_modules/",express("./node_modules/"));
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
//app.set
app.engine("html", require("express-art-template"));
app.get("/index", function (request, response) {
    response.render("index.html");
});
app.listen(9000, function () {
    console.log("server is running!!");
});

我遇到了 CSS 问题。下图说明了它:

这是我的 index.html:

这是我的资源文件夹:

我搜索了很多,但未能修复它。我该怎么做?

【问题讨论】:

  • 欢迎来到 StackOverflow!请改进您的帖子,以便其他人更愿意回答:用实际的 html 替换您的 html 图片,错误的屏幕截图及其文本和描述(当您看到它时,预期的行为是什么,实际的行为是什么)。文件夹结构的图片也应该替换为文本(甚至删除,因为您可能只需要显示 CSS 和 html 的路径)。最好的问候
  • 非常抱歉。你的建议很好。但你知道我的英语不好。编辑一个问题需要我很多时间......但是质量问题并不完美
  • 没问题,只需编辑您的问题并插入代码而不是图片。如果您已经解决了问题,请不要忘记接受您的回答(不过,这可能会在一天后完成)——这样很明显它已经解决了
  • 我明白了!谢谢!

标签: javascript css node.js express


【解决方案1】:

我犯了一个愚蠢的错误。

app.use("/node_modules",express.static("./node_modules"));

【讨论】:

    猜你喜欢
    • 2010-09-09
    • 1970-01-01
    • 2011-02-26
    • 2012-05-20
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    相关资源
    最近更新 更多