javascript - Nodejs TypeError: undefined is not a function -
i'm following treehouse nodejs tutorial , ran error. server response in router unable find view method in renderer.
router.js:10 response.view("header", {}, response); ^ typeerror: undefined not function
renderer.js
var fs = require("fs"); function view(templatename, values, response) { //read template files var filecontents = fs.readfilesync('./views/' + templatename + '.html'); //insert values in content //write out contents response response.write(filecontents); } module.exports.view = view;
router.js
var profile = require("./profile.js"); var renderer = require("./renderer.js"); //handle http route / , post / i.e. home function home(request, response) { //if url == "/" && if(request.url === "/") { //show search response.writehead(200, {'content-type': 'text/plain'}); response.view("header", {}, response); response.write("search\n"); response.end("footer\n"); } }
you not using renderer
anywhere in router.js
.
i believe meant call renderer.view
instead of response.view
.
Comments
Post a Comment