Write a file atomically and use fsync to flush its contents.
Node.js file operations, even
writeFileSync, cannot guarantee that the contents of the file were written.
fs.writeFileSyncis synchronous in the sense that it blocks the event loop while it executes. It does NOT ask the Kernel to do a synchronous write to the underlying file system.
npm install crash-safe-write-file --save
const writeFile = writeFile;;
/*** Fully write or rewrite the datafile, immune to crashes during the write* operation. Writes to a temporary file like `write-file-atomic`, but flushes* all buffers using fsync.** Adapted from .** @param* @param* @param*/;