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 Blazer
James Blazer
3,836 Points

Getting the following error throw new TypeError('First argument must be a string of Buffer');

Adam Beer
Adam Beer
11,314 Points

Please show your code. You can use the snapshot function in the workspace and provide the link to that or

Code

Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

      ```html
      <p>This is code!</p>
      ```
James Blazer
James Blazer
3,836 Points

Hey Adam, I added a link to my files. I noticed a .write in the error. I am wondering if it is the responde.write I have in the code but I did as the instructor did so I am guessing this should work. It might be in one of the other files. Still trying to figure it out. Thanks for the help

2 Answers

James, I was having the same problem because I had stopped watching the video too soon. Andrew also has an error in the video starting about 4:15. I'm seeing that you're missing the

{encoding: "utf8"});

that he ends up adding in.

James Blazer
James Blazer
3,836 Points

Hey Christian, Thanks for replying. I did have that code in before and it still didn't work. Did you get yours to work? I have looked at mine line by line and can't find the error.

I had that error when I did not have this line of code correct in the renderer.js, I think I had just readFile instead of readFileSync

 var fileContents = fs.readFileSync('./views/' + templateName + '.html');