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

James Barrett
James Barrett
13,253 Points

10:44 Cannot advance past this point, console throwing strange error?

Hi guys,

The error: https://i.gyazo.com/399cbe082f7a80fd1983ce8e8521dcf1.png

The code:

router.js:

var Profile = require("./profile.js");
var renderer = require("./renderer.js");

function home(req, res) {
  if(req.url === "/") {
    renderer.view("header", {}, res);
    res.write("Search\n");
    res.write("Footer\n");
  }
}

renderer.js

var fs = require("fs");

function view(templateName, values, res) {
  var fileContents = fs.readFileSync('/.views/' + templateName + '.html');        
    res.write(fileContents);
}

module.exports.view = view;

Screenshot of 'header.html' clearly in the 'views' directory: https://i.gyazo.com/2b571d2a9ab602ed6e2f10bc12f0505e.png

Any idea of what could be going wrong?

Thanks, James.

1 Answer

Michael Liendo
Michael Liendo
15,326 Points
var fileContents = fs.readFileSync('/.views/' + templateName + '.html');

You have /.views and it should be ./views