Chapter 6 -- 03 Serve Static content pauses
The chapter 6 code for "Serve Static Content Pauses" crashes with the error:
TypeError: First argument must be a string or Buffer when it calls: if (!res.write(data))
The function needs the if(data) block used previously.
rs.on('readable', () => {
var data = rs.read();
if(data) {
if (!res.write(data)) {
rs.pause();
}
}
});
I'd love a better explanation of why its needed.
Hi!
Thanks for the note. That's behaviour I haven't seen before. I guess there is now a case where you get a readable, but there's no data to actually read. I suspect the "readable" event is still fired to let you know that it's finished or something.
What version of node is this for? I wonder if it's a change.
I've the same issue when I try to refresh the page. My node version is v8.3.0