0
我在關注Treehouse Nodejs教程並遇到這個錯誤。服務器在路由器中的響應無法在渲染器中查找視圖方法。Nodejs TypeError:undefined不是函數
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");
}
}
**渲染器**。view not response.view –