Awesome Open Source
Awesome Open Source


Write many files atomically

  • Creates temporary files with file contents
  • Moves them all at once using rename()
  • Automatically cleans up after itself
  • Optimized to be as fast as possible
  • Doesn't break file watchers
  • Doesn't swallow errors
  • Includes Flow types


yarn add write-files-atomic


const writeFilesAtomic = require('write-files-atomic');

await writeFilesAtomic([
  { filePath: './foo.txt', fileContents: '' },
  { filePath: './bar.txt', fileContents: '' },
  { filePath: './baz.txt', fileContents: '...baz...' },


type Files = Array<{
  filePath: string,
  fileContents: string | Buffer,
  encoding?: string, // default 'utf8'
  mode?: number,
  chown?: { uid: number, gid: number }, // default `fs.stat` of existing file

declare function writeFilesAtomic(files: Files): Promise<void>;

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (68,032
nodejs (3,632
files (72
fs (29
atomic (23

Find Open Source By Browsing 7,000 Topics Across 59 Categories