render方法报错:TypeError: View is not a function(刚开始研究nodeJS)
小弟刚开始研究node.js 根据网上资料在Windows7上写了个demo server:
var express = require('express');
var app = express();
app.set('view engine','ejs');
app.set('view',__dirname + '/views');
app.get('/',function(req,res){
res.render("home.ejs",{some:"yorkie"});
});
app.listen(3000);
home.ejs:
<html>
<head>
<title> new template </title>
</head>
<body>
<p> Hello Ejs</p>
<p> hi <%= some %></p>
</body>
</html>
node运行后访问3000接口报错细节如下:
TypeError: View is not a function
at EventEmitter.render (D:\nodejs\node_modules\express\lib\application.js:569:12)
at ServerResponse.render (D:\nodejs\node_modules\express\lib\response.js:961:7)
at D:\nodejs\easyExample\express_hello\server2.js:13:9
at Layer.handle [as handle_request] (D:\nodejs\node_modules\express\lib\router\layer.js:95:5)
at next (D:\nodejs\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (D:\nodejs\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\nodejs\node_modules\express\lib\router\layer.js:95:5)
at D:\nodejs\node_modules\express\lib\router\index.js:277:22
at Function.process_params (D:\nodejs\node_modules\express\lib\router\index.js:330:12)
at next (D:\nodejs\node_modules\express\lib\router\index.js:271:10)
请教大神这是出了什么问题
3 回复
补充:home.ejs在server同级别views文件夹下
首先你要把代码格式化一下嘛 view修改为views – app.set(‘views’,__dirname + ‘/views’);
@star45 谢谢你 你解决了我的问题 但是我看网上有个案例就是用的view啊~