Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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