Synchronously write a file and create its ancestor directories if needed
Installations
npm install output-file-sync
Developer Guide
Typescript
No
Module System
N/A
Node Version
9.5.0
NPM Version
5.6.0
Score
98.8
Supply Chain
98.9
Quality
75.3
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
shinnn
Download Statistics
Total Downloads
393,481,959
Last Day
86,171
Last Week
366,851
Last Month
1,931,570
Last Year
30,247,780
GitHub Statistics
15 Stars
44 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Bundle Size
14.15 kB
Minified
4.51 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.1
Package Id
output-file-sync@2.0.1
Size
3.46 kB
NPM Version
5.6.0
Node Version
9.5.0
Publised On
15 Feb 2018
Total Downloads
Cumulative downloads
Total Downloads
393,481,959
Last day
1.3%
86,171
Compared to previous day
Last week
-16.1%
366,851
Compared to previous week
Last month
-1.2%
1,931,570
Compared to previous month
Last year
-4.4%
30,247,780
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
7
output-file-sync
Synchronously write a file and create its ancestor directories if needed
1const {readFileSync} = require('fs'); 2const outputFileSync = require('output-file-sync'); 3 4outputFileSync('foo/bar/baz.txt', 'Hi!'); 5readFileSync('foo/bar/baz.txt', 'utf8'); //=> 'Hi!'
Difference from fs.outputFileSync
This module is very similar to fs-extra's fs.outputFileSync
method, but different in the following points:
- output-file-sync returns the path of the directory created first. See the API document for more details.
- output-file-sync accepts mkdirp options.
1const {statSync} = require('fs'); 2const outputFileSync = require('output-file-sync'); 3 4outputFileSync('foo/bar', 'content', {mode: 33260}); 5statSync('foo').mode; //=> 33260
- output-file-sync validates its arguments strictly, and prints highly informative error message.
Installation
npm install output-file-sync
API
1const outputFileSync = require('output-file-sync');
outputFileSync(path, data [, options])
path: string
data: string
, Buffer
or Uint8Array
options: Object
(options for fs.writeFileSync and mkdirp) or string
(encoding)
Return: string
if it creates more than one directories, otherwise null
It writes the data to a file synchronously. If ancestor directories of the file don't exist, it creates the directories before writing the file.
1const {statSync} = require('fs'); 2const outputFileSync = require('output-file-sync'); 3 4// When the directory `foo/bar` exists 5outputFileSync('foo/bar/baz/qux.txt', 'Hello', 'utf-8'); 6 7statSync('foo/bar/baz').isDirectory(); //=> true 8statSync('foo/bar/baz/qux.txt').isFile(); //=> true
It returns the directory path just like mkdirp.sync:
Returns the first directory that had to be created, if any.
1const dir = outputFileSync('foo/bar/baz.txt', 'Hello'); 2dir === path.resolve('foo'); //=> true
options
All options for fs.writeFileSync and mkdirp are available.
Additionally, you can pass fileMode
and dirMode
options to set different permission between the file and directories.
options.fileMode
Set the mode of a file, overriding mode
option.
options.dirMode
Set the modes of directories, overriding mode
option.
1outputFileSync('dir/file', 'content', {dirMode: '0745', fileMode: '0644'}); 2fs.statSync('dir').mode.toString(8); //=> '40745' 3fs.statSync('dir/file').mode.toString(8); //=> '100644'
Related project
- output-file (asynchronous version)
License
ISC License © 2017 - 2018 Shinnosuke Watanabe
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
38 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2025-01-27
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 MoreOther packages similar to output-file-sync
sync-runner
To execute a binary executable file and return its standard output synchronization.
cy-i18n-sync-cli
sync-i8n [--way <tier|tile>] [--file-type <json|properties>] [--output src/locale] [--registry http://xxx]-p xxx
@puppedo/walk-sync
Synchronously walks through a directory and its subdirectories, returning an array of file paths.
fs-iconv
save file with charset/encoding/iconv