【问题标题】:Nodejs Express - folders inside public folder not workingNodejs Express - 公用文件夹内的文件夹不起作用
【发布时间】:2018-06-22 02:01:04
【问题描述】:

我使用 express 创建了一个 nodejs 应用程序来为我的投资组合和项目提供服务。当访问根目录“/”时,我的投资组合工作正常,但是当我为“/FootballScores”和“/FacebookGrabber”之类的项目提供服务时,一个工作一半(意味着所有角度文件已成功加载,但仍不显示任何内容)和另一个项目未加载并显示错误:

“错误:找不到模块'html'”

我还安装了所有的 npm 包。这是 app.js 代码:

var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
nodemailer = require("nodemailer"),
xoauth2 = require("xoauth2"),
path = require("path");

app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.urlencoded({extended: true}));

app.get("/", function(req, res){
res.render("index.html");
});

app.get("/FacebookGrabber", function(req, res){
res.render("FacebookGrabber/index.html");
});

app.get("/FootballScores", function(req, res){
res.render("FootballScores/index.html");
});

app.listen(3000, process.env.IP, function(){
console.log("Portfolio Server Started!");
});

我认为问题是由于公共路径不正确...我该怎么做才能让我的项目 /FootballScores 和 /FacebookGrabber 也正确加载?

【问题讨论】:

  • 投资组合在根“/”上正确提供,FootballScores 的工作方式与以前相同,在“/FacebookGrabber”上出现此文本:“FacebookGrabber/index.html”而不是“错误:找不到模块'html'"
  • 您看过了吗:stackoverflow.com/questions/16111386/… 在没有引擎的情况下同时使用express/staticrender 似乎存在问题。
  • 对不起兄弟,这是我复制 FacebookGrabber 文件夹时的错误,它是空的,没有 index.html 文件。感谢您的帮助。
  • 常见错误,不用担心

标签: node.js express


【解决方案1】:

您是否尝试在调用 res.render 之前将视图引擎设置为 html?

// View engine
app.set('view engine', 'html');

【讨论】:

    【解决方案2】:

    对不起,我复制 FacebookGrabber 文件夹时是我的错误,它是空的,没有 index.html 文件。感谢您的帮助。

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2012-07-20
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      相关资源
      最近更新 更多