Handlebars 仅在 运行 作为服务时查找失败

Handlebars Fails Lookup Only When Running As Service

当 运行 通过 npm 在我项目的根目录中时,我在本地和服务器机器上都没有问题,但是当 运行 作为服务 handlebars 无法找到我的视图文件和输出时这个错误到我的日志:

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");
})

...

我从来没有弄清楚,而是选择了 this tutorial and set up my service with pm2.