Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Build a Simple Dynamic Site with Node.js Creating a Basic Template Engine in Node.js Reading from Files

Noora Kurko
Noora Kurko
7,785 Points

Hi! I get a "renderer.view is not a function" error from this assignment.

//renderer.js:

const fs = require('fs');

function view(templateName, values, response) { fs.readFile('./views/' + templateName + '.html', function (error, fileContents) { if (error) throw error; response.write(fileContents);
});

module.exports.view = view;

}

//router.js (the part that matters here):

const renderer = require("./renderer.js");

function home(request, response) { if (request.url === "/") { response.writeHead(200, {'Content-Type': 'text/plain'}); renderer.view("header", {}, response); response.write("Search\n"); response.end("Footer\n"); } }

1 Answer

Noora Kurko
Noora Kurko
7,785 Points

Problem solved! Had the module.exports.view = view; inside the curly braces :)