簡體   English   中英

Node.js TypeError:未定義不是函數

[英]Nodejs TypeError: undefined is not a function

我正在遵循Treehouse Node.js教程並遇到此錯誤。 路由器中的服務器響應無法在渲染器中找到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");
 }
}

您不在router.js任何地方使用renderer

我相信您打算將其稱為renderer .view而不是response.view

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM