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 trialCarlos Chavez
5,691 PointsWhy did the buffer work before trying to merge content with values?
I understood the part when Andrew said we needed to convert the buffer to a string.
I'm only wondering, why this didn't affect the website before? It was rendering in a way we could see the content with the placeholders "{{}}". I mean, we were already using the 'renderer.view()', and without the encoding. Maybe I'm missing something in the process. Thank you guys for any clarification!
1 Answer
Courtney Wilson
8,031 PointsJust wanted to answer for anyone else who might be wondering the same thing. The response.write() method accepts a buffer as an argument. Buffer has a toString() method and the response.write() method uses this in its underlying code to write the buffer to the page as a string. In the mergeValues() function, we were trying to use fileContents as a string object by using String's replace() method. It had not been established as a string, only as a buffer and it was never converted until we added the encoding to the readFileSync() method. I'm not sure if it's bad practice or not but for testing purposes at least, you can just as easily use the toString() method on fileContents as an argument in mergeValues() and it would work.