Nodejs Express - 公用文件夹中的文件夹无法正常工作

时间:2018-01-12 15:17:06

标签: node.js express

我使用express创建了一个nodejs应用程序来为我的投资组合和我的项目服务。当访问root时我的投资组合正常工作" /"但当我为我的项目提供服务时,比如" / 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也能正确加载?

2 个答案:

答案 0 :(得分:0)

很抱歉,伙计们,我复制FacebookGrabber文件夹时出错是空的,没有index.html文件。谢谢你的帮助。

答案 1 :(得分:0)

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

// View engine
app.set('view engine', 'html');
相关问题