帕格`2.0.0 beta 5`,表达节点6+

时间:2016-11-20 14:53:57

标签: javascript node.js express pug

今天,90%的免费日我想测试一些“技术”,我发现herokunodeJS将是一个很好的主题。

本教程使用ejs模板,我想将它们更改为jade(不转换,只使用jade),因此我在项目中添加了pug

请查看我的index.jsnode 6.2.0

var express = require('express');
var app = express();
// const RouteService = require('./server/services/RouteService');

app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'pug')
app.set('views', __dirname + '/views');
// RouteService.registerRoutes(app);
app.get('/', function(request, response) {
  response.render('/pages/index', { title: 'Hey Hey Hey!', message: 'Yo Yo'});
});

app.listen(app.get('port'), function() {
  console.log('Node app is running on port', app.get('port'));
});

所以这主要是heroku模板。index.js在主文件夹中是./index.jsindex.jade./views/pages/index.jade

错误(本地与node index.js和heroku(同一命令))是

Error: Failed to lookup view "/pages/index" in views directory "/home/daniel/Pulpit/crystal-fan-prototype/views"
    at EventEmitter.render (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/application.js:579:17)
    at ServerResponse.render (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/response.js:961:7)
    at /home/daniel/Pulpit/crystal-fan-prototype/index.js:16:12
    at Layer.handle [as handle_request] (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/layer.js:95:5)
    at /home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/index.js:330:12)
    at next (/home/daniel/Pulpit/crystal-fan-prototype/node_modules/express/lib/router/index.js:271:10)

我觉得我有一个我无法识别的非常微不足道的问题,谢谢你的建议!

(在/上获取localhost:5000后服务器开始正确监听后出现此错误

0 个答案:

没有答案