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 Binding Values

Error: ENOENT: no such file or directory

Hello,

Im trying to run my code but im getting this error on node. var fs = require('fs');

function mergeValues(values, content) { //Cycle over the keys //Replace all {{key}} with the value from the values object. for(var key in values) { content = content.replace("{{" + key + "}}", values[key]); } //return merge content return content; }

function view(templatename, values, response) { //read from the template file

var fileContents = fs.readFileSync("./views/" + templatename + ".html", {encoding: "utf8"}).toString();
fileContents = mergeValues(values, fileContents);
response.write(fileContents);

};

module.exports.view = view;

I dont understand why its not finding my files in the views folder. Can someone please help me ?

2 Answers

someone had the exact same problem as me some time ago and created a github with the code : https://github.com/jg-digital-media/node-site . maybe it will be easier to read the code in here?