今天,90%的免费日我想测试一些“技术”,我发现heroku
和nodeJS
将是一个很好的主题。
本教程使用ejs
模板,我想将它们更改为jade(不转换,只使用jade),因此我在项目中添加了pug
。
请查看我的index.js
(node 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.js
,index.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
后服务器开始正确监听后出现此错误