当我在项目的根目录中通过npm运行时,我在本地和服务器的机器上都没有问题,但是当作为服务运行时,把手无法找到我的视图文件并输出此错误到我的日志:
server listening...
Connected
Error: Failed to lookup view "home" in views directory "/views"
at EventEmitter.render (/var/www/dopWeb/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/var/www/dopWeb/node_modules/express/lib/response.js:966:7)
at /var/www/dopWeb/index.js:45:13
at Layer.handle [as handle_request] (/var/www/dopWeb/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/dopWeb/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/dopWeb/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/dopWeb/node_modules/express/lib/router/layer.js:95:5)
at /var/www/dopWeb/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/var/www/dopWeb/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/dopWeb/node_modules/express/lib/router/index.js:275:10)
我有一个非常标准的配置文件:
description "dop webserver"
author "Mike Pawlak"
start on started mountall
stop on shutdown
# automatically respawn
respawn
respawn limit 99 5
script
export HOME="/root"
exec /usr//bin/nodejs /var/www/dopWeb/bin/www >> /var/log/node.log 2>&1
end script
和目录结构 -
Index.js代码:
...
//rendering engine setup
var handlebars = require('express-handlebars')
.create({defaultLayout: 'main'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
...
app.get('/', function(req, res) {
res.render("/home");
})
...