output-file
Write a file and create its ancestor directories if needed
const readFile = promises;const outputFile = ; async { await ; await ; //=> 'Hi!'};
This module is very similar to fs-extra's fs.outputFile
, but has the following features fs-extra doesn't have:
- Support for various non-string path types –
Buffer
,Uint8Array
andURL
- An option to set mode of created directories
Installation
npm install output-file
API
const outputFile = ;
outputFile(path, data [, options])
path: string | Buffer | Uint8Array | URL
data: string | Buffer | TypedArray | DataView
options: Object
(options) or string
(file encoding)
Return: Promise<undefined>
It writes the data to a file asynchronously. If ancestor directories of a file don't exist, it creates those directories before writing a file.
const stat = promises;const outputFile = ; // When the directory `foo/bar` exists async { await ; await ; //=> true await ; //=> true};
options
All options for fs.promises.writeFile()
and fs.promises.mkdir()
, except for mode
and recursive
, are supported.
recursive
option is enabled by default and cannot be disabled.
Instead of mode
option, use the followings:
options.fileMode
Set mode of a file.
options.dirMode
Set mode of directories.
const stat = promises;const outputFile = ; async { await ; await mode; //=> '40745' await mode; //=> '100644'};
Related project
- output-file-sync (synchronous version)
License
ISC License © 2018 - 2019 Shinnosuke Watanabe