Gathering detailed insights and metrics for write
Gathering detailed insights and metrics for write
Gathering detailed insights and metrics for write
Gathering detailed insights and metrics for write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
npm install write
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.4
Supply Chain
100
Quality
77.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
2,397,445,460
Last Day
44,813
Last Week
44,813
Last Month
10,459,381
Last Year
212,532,429
83 Stars
57 Commits
8 Forks
6 Watching
1 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
write@2.0.0
Size
5.65 kB
NPM Version
6.10.0
Node Version
12.7.0
Publised On
04 Sept 2019
Cumulative downloads
Total Downloads
Last day
0%
44,813
Compared to previous day
Last week
-97.9%
44,813
Compared to previous week
Last month
-19.6%
10,459,381
Compared to previous month
Last year
-20.5%
212,532,429
Compared to previous year
1
3
Write data to a file, replacing the file if it already exists and creating any intermediate directories if they don't already exist. Thin wrapper around node's native fs methods.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm (requires Node.js >=10):
1$ npm install --save write
1const write = require('write');
The following options may be used with any method.
Type: boolean
Default: undefined
Ensure that contents has a trailing newline before writing it to the file system.
1write.sync('foo.txt', 'some data...', { newline: true });
Type: boolean
Default: undefined
Set to false
to prevent existing files from being overwritten. See increment for a less severe alternative.
1write.sync('foo.txt', 'some data...', { overwrite: false });
Type: boolean
Default: undefined
Set to true
to automatically rename files by appending an increment, like foo (2).txt
, to prevent foo.txt
from being overwritten. This is useful when writing log files, or other information where the file name is less important than the contents being written.
1write.sync('foo.txt', 'some data...', { increment: true }); 2// if "foo.txt" exists, the file will be renamed to "foo (2).txt"
Asynchronously writes data to a file, replacing the file if it already exists and creating any intermediate directories if they don't already exist. Data can be a string or a buffer. Returns a promise if a callback function is not passed.
Params
filepath
{String}: file path.data
{String|Buffer|Uint8Array}: Data to write.options
{Object}: Options to pass to fs.writeFilecallback
{Function}: (optional) If no callback is provided, a promise is returned.returns
{Object}: Returns an object with the path
and contents
of the file that was written to the file system. This is useful for debugging when options.increment
is used and the path might have been modified.Example
1const write = require('write'); 2 3// async/await 4(async () => { 5 await write('foo.txt', 'This is content...'); 6})(); 7 8// promise 9write('foo.txt', 'This is content...') 10 .then(() => { 11 // do stuff 12 }); 13 14// callback 15write('foo.txt', 'This is content...', err => { 16 // do stuff with err 17});
The synchronous version of write. Returns undefined.
Params
filepath
{String}: file path.data
{String|Buffer|Uint8Array}: Data to write.options
{Object}: Options to pass to fs.writeFileSyncreturns
{Object}: Returns an object with the path
and contents
of the file that was written to the file system. This is useful for debugging when options.increment
is used and the path might have been modified.Example
1const write = require('write'); 2write.sync('foo.txt', 'This is content...');
Returns a new WriteStream object. Uses fs.createWriteStream
to write data to a file, replacing the file if it already exists and creating any intermediate directories if they don't already exist. Data can be a string or a buffer.
Params
filepath
{String}: file path.options
{Object}: Options to pass to fs.createWriteStreamreturns
{Stream}: Returns a new WriteStream object. (See Writable Stream).Example
1const fs = require('fs'); 2const write = require('write'); 3fs.createReadStream('README.md') 4 .pipe(write.stream('a/b/c/other-file.md')) 5 .on('close', () => { 6 // do stuff 7 });
See [CHANGELOG.md].
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Commits | Contributor |
---|---|
42 | jonschlinkert |
2 | jpetitcolas |
1 | tunnckoCore |
Jon Schlinkert
Copyright © 2019, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on September 04, 2019.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-03
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-file-atomic
Write files in an atomic fashion w/configurable ownership
flush-write-stream
A write stream constructor that supports a flush function that is called before finish is emitted
fs-write-stream-atomic
Like `fs.createWriteStream(...)`, but atomic.
write-json-file
Stringify and write JSON to a file atomically