我在Heroku上启动了一个新的nodejs项目。代码在我的机器上运行得很好,但是当我在Heroku上运行时,我得到了这样的信息:
无法在视图目录“/ app / server / views”中查找视图“index.jade”
知道我有目录“/ app / server / views”中的“index.jade”文件。
操作系统:Windows 10。
Server.js文件
var express = require('express');
var path = require ('path');
var connectionString = "mongodb://localhost:27017/TravelWithMe";
stylus = require ('stylus');
logger = require('morgan');
bodyParser = require('body-parser');
mongoose = require('mongoose');
var app = express();
function compile (str,path)
{
return stylus(str).set('filename',path);
}
app.set('views',path.join(__dirname ,'server/views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(stylus.middleware(
{
src: path.join(__dirname ,'public'),
compile: compile
}
));
app.use(express.static(path.join(__dirname ,'public')));
mongoose.connect(connectionString);
var db = mongoose.connection;
db.on('error',console.error.bind(console,'connection error ...'));
db.once('open',function callback() {
console.log('TWM Db opened')
});
app.get('/partials/:partialPath', function(req, res) {
res.render('partials/' + req.params.partialPath);
});
app.get('*',function (req,resp){
resp.render('index.jade',{MongoMessage : MongoMessage});
});
var port = process.env.PORT || 3030;
app.listen(port);
答案 0 :(得分:0)
所以我找到了让它运转的方法。我删除了index.jade文件并重新创建了它!