I use fs.readFile
and fs.writeFile
a lot, often repeatedly reading/writing the same file paths.
Would it be better for performance to open each file with fs.open
once, and then reuse the same fd
repeatedly (with fs.read
or fs.write
)?
Opening a file is a very, very expensive process. You are best served by keeping the file descriptor active and then just read/write at will. The only time you need depart from this is when you run short of file descriptors.