From e6dfb9fe81310ccbc28425af1935c6bd918bc480 Mon Sep 17 00:00:00 2001 From: webdevelopersrinu Date: Thu, 3 Sep 2026 08:09:25 +0530 Subject: [PATCH] fs: add atomic option to writeFile Writes go to a temp file next to the target and then get renamed over it, so a reader never sees a half written file. Refs: https://github.com/nodejs/node/issues/49886 Signed-off-by: webdevelopersrinu --- doc/api/fs.md | 27 +++ lib/fs.js | 87 +++++++- lib/internal/fs/promises.js | 37 ++++ lib/internal/fs/utils.js | 29 +++ test/parallel/test-fs-write-file-atomic.js | 243 +++++++++++++++++++++ 5 files changed, 422 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-fs-write-file-atomic.js diff --git a/doc/api/fs.md b/doc/api/fs.md index 1ad902ad5fb6..bf6bd2845474 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2287,6 +2287,9 @@ All the [caveats][] for `fs.watch()` also apply to `fsPromises.watch()`.