RangeError: length > kMaxLength while reading massive text file with NodeJS

I have a huge(~1.5 gig) text file to read with 'fs' and it gives me back this error:

RangeError
RangeError: length > kMaxLength
    at new Buffer (buffer.js:242:21)
    at fs.js:130:16
    at Object.oncomplete (fs.js:297:15)

Here is part of my code:

var fs = require('fs');
fs.readFile('file.txt', 'ASCII', function (err, data) {
  console.log(data)
});

It gets me back error even though i use this command: node --max-old-space-size=8000 file.js Any suggestions are welcome:) Thank you!

Even for a 64-bit install, you can't increase the memory limit beyond ~1.7GB (~1GB for 32-bit). See the FAQ. So you can't set --max-old-space-size beyond that limit.

Can you use a streaming read interface to the file instead?

As JohnnyHK mentioned, using streams is the right solution. Use fs.createReadStream to create streams from the file system:

fs.createReadStream('file.txt', {encoding: 'ASCII'}).pipe(process.stdout)