Skip to content
Advertisement

nodejs – replace a string everywhere in a large file

I have some huge files which are difficult to read in memory. I need to read each line and then replace double quotes if found and edit the same file. Right now, I am reading the file line by line, storing in an array and overwriting the same file. But, that’s giving memory issue for big files. Any pointers ? Here is my present implementation :

JavaScript

Is there a way to edit by reading one line at a time and changing that in the file?

I have seen the similar question with scramjet, but that gives an error and is not compatible with all nodejs versions : node.js modify file data stream?

Advertisement

Answer

After going through a lot of answers, this worked for me which took care of the required synchronous and asynchronous behaviour, large file and keeping the name same.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement