我正在追踪Treehouse Nodejs教程,并遇到此错误。路由器中的服务器响应无法在渲染器中找到view方法。
router.js:10
response.view("header", {}, response);
^
TypeError: undefined is not a function
renderer.js
var fs = require("fs");
function view(templateName, values, response) {
//Read from the template files
var fileContents = fs.readFileSync('./views/' + templateName + '.html');
//Insert values in to the content
//Write out the contents to the response
response.write(fileContents);
}
module.exports.view = view;
router.js
var Profile = require("./profile.js");
var renderer = require("./renderer.js");
//Handle HTTP route GET / and POST / i.e. Home
function home(request, response) {
//if url == "/" && GET
if(request.url === "/") {
//show search
response.writeHead(200, {'Content-Type': 'text/plain'});
response.view("header", {}, response);
response.write("Search\n");
response.end("Footer\n");
}
}
您不在中的renderer
任何地方router.js
。
我相信您是要打电话renderer.view
代替response.view
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句