Fixing Node error: “Invalid string length”

If you concatenate strings in Node, you may get an error like so:

$ node select.js
C:\projects\image-annotation\data\talks\json\select.js:24
      all_transcripts = all_transcripts + "\n" + transcript;
                                               ^

RangeError: Invalid string length
    at fs.stat (C:\projects\image-annotation\data\talks\json\select.js:24:48)
    at FSReqWrap.oncomplete (fs.js:123:15)

This is actually an out of memory error. The fix is to rewrite your code, so that it operates on each bit of text in sequence, and discard the output. For instance, you might switch to appending the output to a file:

fs.appendFileSync('transcripts.txt', transcript);