What’s the best way to overwrite a line in a large (2MB+) text file using node.js?
My current method involves
- copying the entire file into a buffer.
- Spliting the buffer into an array by the new line character (
\n). - Overwriting the line by using the buffer index.
- Then overwriting the file with the buffer after join with
\n.
First, you need to search where the line starts and where it ends. Next you need to use a function for replacing the line. I have the solution for the first part using one of my libraries: Node-BufferedReader.