Gathering detailed insights and metrics for atomically
Gathering detailed insights and metrics for atomically
Gathering detailed insights and metrics for atomically
Gathering detailed insights and metrics for atomically
npm install atomically
Typescript
Module System
Node Version
NPM Version
99.3
Supply Chain
99.6
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (70.04%)
TypeScript (29.96%)
Total Downloads
106,759,746
Last Day
78,404
Last Week
1,533,491
Last Month
6,480,140
Last Year
55,266,700
MIT License
167 Stars
64 Commits
11 Forks
3 Watchers
1 Branches
2 Contributors
Updated on Jun 09, 2025
Minified
Minified + Gzipped
Latest Version
2.0.3
Package Id
atomically@2.0.3
Unpacked Size
74.52 kB
Size
15.58 kB
File Count
27
NPM Version
10.2.3
Node Version
18.19.0
Published on
Apr 04, 2024
Cumulative downloads
Total Downloads
Last Day
10.3%
78,404
Compared to previous day
Last Week
-5.4%
1,533,491
Compared to previous week
Last Month
7.5%
6,480,140
Compared to previous month
Last Year
104%
55,266,700
Compared to previous year
2
7
Read and write files atomically and reliably.
write-file-atomic
, with some important enhancements on top, you can largely use this as a drop-in replacement.write-file-atomic
, and it can be 10x faster, while being essentially just as safe, by using the fsyncWait
option.write-file-atomic
.write-file-atomic
does, by default retrying some failed operations and handling some more errors.ENOSYS
errors on chmod
/chown
operations are ignored.EINVAL
/EPERM
errors on chmod
/chown
operations, in POSIX systems where the user is not root, are ignored.EMFILE
/ENFILE
/EAGAIN
/EBUSY
/EACCESS
/EACCES
/EACCS
/EPERM
errors happening during necessary operations are caught and the operations are retried until they succeed or the timeout is reached.ENAMETOOLONG
errors, both appening because of the final path or the temporary path, are attempted to be worked around by smartly truncating paths..tmp-[timestamp][randomness]
suffix to destination paths:
tmp-
part gives users a hint about the nature of these files, if they happen to see them.[timestamp]
part consists of the 10 least significant digits of a milliseconds-precise timestamp, making it likely that if more than one of these files are kept on disk the user will see them in chronological order.[randomness]
part consists of 6 random hex characters.chown
: it allows you to specify custom group and user ids:
false
the default ids are used.encoding
: it allows you to specify the encoding of the file content:
utf8
is used when.fsync
: it allows you to control whether the fsync
syscall is triggered right after writing the file or not:
false
the syscall won't be triggered.fsyncWait
: it allows you to control whether the triggered fsync
is waited or not:
false
the syscall will still be triggered but not be waited.
fsync
fails anyway.mode
: it allows you to specify the mode for the file:
false
then 0o666
is used.schedule
: it's a function that returns a promise that resolves to a disposer function, basically it allows you to provide some custom queueing logic for the writing operation, allowing you to perhaps wire atomically
with your app's main filesystem job scheduler:
schedule
function is provided write operations will still be queued internally by the library too.timeout
: it allows you to specify the amount of maximum milliseconds within which the library will retry some failed operations:
0
or -1
no failed operations will be retried.tmpCreate
: it's a function that will be used to create the custom temporary file path in place of the default one:
ENAMETOOLONG
errors.tmpCreated
: it's a function that will be called with the newly created temporary file path.tmpPurge
: it allows you to control whether the temporary file will be purged from the filesystem or not if the write fails:
false
it will be kept on disk.1npm install --save atomically
This is the shape of the optional options object:
1type Disposer = () => void; 2 3type ReadOptions = string | { 4 encoding?: string | null, 5 mode?: string | number | false, 6 timeout?: number 7}; 8 9type WriteOptions = string | { 10 chown?: { gid: number, uid: number } | false, 11 encoding?: string | null, 12 fsync?: boolean, 13 fsyncWait?: boolean, 14 mode?: string | number | false, 15 schedule?: ( filePath: string ) => Promise<Disposer>, 16 timeout?: number, 17 tmpCreate?: ( filePath: string ) => string, 18 tmpCreated?: ( filePath: string ) => any, 19 tmpPurge?: boolean 20};
This is the shape of the provided functions:
1function readFile ( filePath: string, options?: ReadOptions ): Promise<Buffer | string>; 2function readFileSync ( filePath: string, options?: ReadOptions ): Buffer | string; 3function writeFile ( filePath: string, data: Buffer | string | undefined, options?: WriteOptions ): Promise<void>; 4function writeFileSync ( filePath: string, data: Buffer | string | undefined, options?: WriteOptions ): void;
This is how to use the library:
1import {readFile, readFileSync, writeFile, writeFileSync} from 'atomically'; 2 3// Asynchronous read with default option 4const buffer = await readFile ( '/foo.txt' ); 5 6// Synchronous read assuming the encoding is "utf8" 7const string = readFileSync ( '/foo.txt', 'utf8' ); 8 9// Asynchronous write with default options 10await writeFile ( '/foo.txt', 'my_data' ); 11 12// Asynchronous write that doesn't prod the old file for a stat object at all 13await writeFile ( '/foo.txt', 'my_data', { chown: false, mode: false } ); 14 15// 10x faster asynchronous write that's less resilient against imminent catastrophies 16await writeFile ( '/foo.txt', 'my_data', { fsync: false } ); 17 18// 10x faster asynchronous write that's essentially still as resilient against imminent catastrophies 19await writeFile ( '/foo.txt', 'my_data', { fsyncWait: false } ); 20 21// Asynchronous write with a custom schedule function 22await writeFile ( '/foo.txt', 'my_data', { 23 schedule: filePath => { 24 return new Promise ( resolve => { // When this returned promise will resolve the write operation will begin 25 MyScheduler.schedule ( filePath, () => { // Hypothetical scheduler function that will eventually tell us to go on with this write operation 26 const disposer = () => {}; // Hypothetical function that contains eventual clean-up logic, it will be called after the write operation has been completed (successfully or not) 27 resolve ( disposer ); // Resolving the promise with a disposer, beginning the write operation 28 }) 29 }); 30 } 31}); 32 33// Synchronous write with default options 34writeFileSync ( '/foo.txt', 'my_data' );
MIT © Fabio Spampinato
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morewrite-json-file
Stringify and write JSON to a file atomically
write-yaml-file
Stringify and write YAML to a file atomically
atomically-universal
A wrapper around [atomically](https://github.com/fabiospampinato/atomically) that enables it to also run in the browser by writing to indexed db.
fast-write-atomic
Fast way to write a file atomically, for Node.js