Reputation: 118
I'm following Treehouse Nodejs tutorial and ran into this error. Server response in router is unable to find the view method in renderer.
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");
}
}
Upvotes: 0
Views: 497
Reputation: 816374
You are not using renderer
anywhere in router.js
.
I believe you meant to call renderer.view
instead of response.view
.
Upvotes: 1