我正在尝试使用Dropbox Sync在Heroku上部署应用程序,但它表示内部服务器错误,日志显示:
2016-08-04T16:39:11.536583+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-08-04T16:39:11.536571+00:00 app[web.1]: Error: Cannot find module 'html'
2016-08-04T16:39:11.533835+00:00 heroku[router]: at=info method=GET path="/" host=comboracle.herokuapp.com request_id=3d60846c-2426-4a6f-a7a9-dbf89e5786b5 fwd="174.67.241.64" dyno=web.1 connect=0ms service=79ms status=500 bytes=232
我的index.js文件设置如下:
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public');
app.get('/', function(request, response) {
response.render('public/handcheck.html');
});
app.listen(app.get('port'), function() {
console.log('The app is live on port' + app.get('port'));
});
我的package.json看起来像这样:
{
"name": "combo-oracle",
"description": "combo probability evaluator for tcgs",
"repository": "https://github.com/heroku/comboracle",
"keywords": ["node", "express", "static"],
"scripts": {
"start": "node index.js"
},
"version": "0.0.1",
"dependencies": {
"express": "*"
}
}
据我了解,html不应该要求任何特定的模块工作。我的本地测试显示渲染.html文件有效,但我不确定这里发生了什么。
答案 0 :(得分:0)
如果没有定义视图引擎,则无法使用response.render
。如果您想使用render
方法,则需要才能使用ejs之类的视图引擎。
如果您只想渲染静态HTML文件,可以这样做:
var express = require('express');
var ejs = require('ejs');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public');
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
app.get('/', function(request, response) {
response.render('public/handcheck.html');
});
app.listen(app.get('port'), function() {
console.log('The app is live on port' + app.get('port'));
});