2 ms·
> this means to write the new file under a separate name and then renaming the new file to replace the old file only after it has been successfully written as t
by int_19h 8y ago
> this means to write the new file under a separate name and then renaming the new file to replace the old file only after it has been successfully written as to provide safety against storage corruption
I agree, that's about the only bit of complexity in all this. But it's completely generic, so it can be made into a small library, and then reused without dealing with the complexity every time. For example:
https://www.npmjs.com/package/write-file-atomic https://www.npmjs.com/package/write-file-atomic