Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t使用OS X 10.11.4,Node.js获取res.render进行渲染。快速3把手_Javascript_Jquery_Node.js_Express_Handlebars.js - Fatal编程技术网

Javascript Can';t使用OS X 10.11.4,Node.js获取res.render进行渲染。快速3把手

Javascript Can';t使用OS X 10.11.4,Node.js获取res.render进行渲染。快速3把手,javascript,jquery,node.js,express,handlebars.js,Javascript,Jquery,Node.js,Express,Handlebars.js,我对这一切都不熟悉。我已经完成了几个不同的教程,将获得相同的结果。我觉得有些东西与设置不兼容,或者我有点胖。以下是我认为相关的文件。我可以让res.send开始工作,但res.render不会渲染。我甚至不能让它抛出500或404错误。虽然没有显示文本,但它似乎找到了。我正在使用OSX10.11.4,Node.js。3把手 directory: /Users/williamshaw/WebProjects/sicmobile Williams-MacBook:sicmobile william

我对这一切都不熟悉。我已经完成了几个不同的教程,将获得相同的结果。我觉得有些东西与设置不兼容,或者我有点胖。以下是我认为相关的文件。我可以让res.send开始工作,但res.render不会渲染。我甚至不能让它抛出500或404错误。虽然没有显示文本,但它似乎找到了。我正在使用OSX10.11.4,Node.js。3把手

directory:
/Users/williamshaw/WebProjects/sicmobile

Williams-MacBook:sicmobile williamshaw$ ls

package.json    resources   sicmobile.js    views

bin node_modules    public  routes  vendors




sicmobile.js:

var path = require('path');
var express = require('express');

// set up handlebars view engine
var exphbs = require('express3-handlebars');
var app = express();

app.set('views', path.join(__dirname, '/views'));
app.engine('handlebars',
exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res) {
res.render('home');
});
app.get('/about', function(req,res){
res.render('about');
});

// 404 catch-all handler (middleware)
app.use(function(req, res, next){
res.status(404);
res.render('404');
});

// 500 error handler (middleware)
app.use(function(err, req, res, next){
console.error(err.stack);
res.status(500);
res.render('500');
});

app.listen(app.get('port'), function(){
 console.log( 'Express started on http://localhost:' +
   app.get('port') + '; press Ctrl-C to terminate.' );
});

main.handlebars:

<!doctype html>
<html>
<head>
  <title>The Company>/title>
</head>
<body>
  <div style='position: absolute; top: 0; height: 40px;'>
    <h3> This is the header</h3>
  </div>

</div style='margin-top: 60px;'>
      {{{ body }}}
  </div>
<div style='position: absolute; bottom: 0;height:40px;'>
</div>

</body>
</html>

home.handlebars:

<!doctype html>
<h1>Welcome to Shaw Investment Company</h1>

about.handlebars:
<h1>This is the  About page.</h1>

400.handlebars:

<h1>404 - Not Found</h1>

500.handlebars:
<h1>500 - Server Error</h1>
目录:
/用户/williamshaw/WebProjects/sicmobile
Williams MacBook:sicmobile williamshaw$ls
package.json资源sicmobile.js视图
bin节点\u模块公共路由供应商
sicmobile.js:
var path=require('path');
var express=需要(“express”);
//设置车把视图引擎
var exphbs=require('express3-handlebar');
var-app=express();
app.set('views',path.join('u_dirname',/views');
发动机附件(“把手”,
exphbs({defaultLayout:'main'}));
应用程序集(“查看引擎”、“把手”);
应用程序集('port',process.env.port | | 3000);
app.use(express.static(uu dirname+/public));
app.get('/',函数(req,res){
res.render(“家”);
});
app.get('/about',函数(req,res){
res.render('about');
});
//404捕获所有处理程序(中间件)
应用程序使用(功能(请求、恢复、下一步){
物质状态(404);
res.render('404');
});
//500错误处理程序(中间件)
应用程序使用(功能(错误、请求、恢复、下一步){
控制台错误(错误堆栈);
物质状态(500);
res.render('500');
});
app.listen(app.get('port'),function(){
console.log('Express已在上启动http://localhost:' +
app.get('port')+';按Ctrl-C终止');
});
主把手:
公司>/title>
这是标题
{{{body}}}
home.Handlebar:
欢迎来到邵氏投资公司
关于车把:
这是关于页面。
400.车把:
404-找不到
500.车把:
500-服务器错误

您在
main.handlebar
中输入错误

<title>The Company</title>
公司
如果您在开发者控制台中检查页面元素,您将在title标记本身中看到数据


希望有帮助。

@Mukwah就是这么做的!谢谢我看了好几个小时都看不见。