File System APIs
The File System APIs enable interacting with the file system in a way modeled on standard POSIX functions.
- Source:
- See:
Classes
Methods
(static) copyFile(source, destination) → {Promise}
Copies asynchronously a file from the source path to destination path.
Parameters:
Name | Type | Description |
---|---|---|
source |
String
|
The path of the source file to be copied. |
destination |
String
|
The path where the source file will be copied to. |
Returns:
- Type:
-
Promise
(static) copyFileSync(source, destination)
Copies synchronously a file from the source path to destination path.
Parameters:
Name | Type | Description |
---|---|---|
source |
String
|
The path of the source file to be copied. |
destination |
String
|
The path where the source file will be copied to. |
(static) createReadStream(path, optionsopt) → {AsyncGeneratorFunction}
Returns a new readable IO stream.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file to be read. |
|||||||||
options |
String
|
Object
|
<optional> |
Configuration options for the stream.
|
Returns:
- Type:
-
AsyncGeneratorFunction
- An instance of a
Readable
stream.
(static) createWriteStream(path, optionsopt) → {Object}
Returns a new writable IO stream.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file where data will be written. |
|||||||||
options |
String
|
Object
|
<optional> |
Configuration options for the stream.
|
Returns:
- Type:
-
Object
An instance of a Writable
stream.
(static) mkdir(path, optionsopt) → {Promise}
Creates directories asynchronously.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path where the new directory will be created. |
|||||||||
options |
Object
|
<optional> |
Configuration options for directory creation.
|
Returns:
- Type:
-
Promise
(static) mkdirSync(path, optionsopt)
Creates directories synchronously.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path where the new directory will be created. |
|||||||||
options |
Object
|
<optional> |
Configuration options for directory creation.
|
(static) open(path, mode) → {Promise.<File>}
Asynchronously opens a file.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The file path of the file to be opened. |
mode |
String
|
The mode in which the file is to be opened. |
Returns:
- Type:
-
Promise.<File>
An instance of the File class.
(static) openSync(path, mode) → {File}
Synchronously opens a file.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The file path of the file to be opened. |
mode |
String
|
The mode in which the file is to be opened. |
Returns:
- Type:
-
File
An instance of the File class.
(static) readFile(path, optionsopt) → {Promise.<(String|Uint8Array)>}
Reads asynchronously the entire contents of a file.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file to be read. |
|||||||||
options |
String
|
Object
|
<optional> |
The options to control the file read operation.
|
Returns:
- Type:
-
Promise.<(String|Uint8Array)>
- The contents of the file.
(static) readFileSync(path, optionsopt) → {String|Uint8Array}
Reads synchronously the entire contents of a file.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file to be read. |
|||||||||
options |
String
|
Object
|
<optional> |
The options to control the file read operation.
|
Returns:
- Type:
-
String
|Uint8Array
- The contents of the file.
(static) readdir(path) → {Promise.<Array.<String>>}
Reads asynchronously the contents of a directory.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The path of the directory whose contents are to be read. |
Returns:
- Type:
-
Promise.<Array.<String>>
An array of strings, where each string is the name of a file or directory.
(static) readdirSync(path) → {Array.<String>}
Reads the contents of a directory.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The path of the directory whose contents are to be read. |
Returns:
- Type:
-
Array.<String>
An array of strings, where each string is the name of a file or directory.
(static) rename(from, to) → {Promise}
Renames oldPath to newPath asynchronously.
Parameters:
Name | Type | Description |
---|---|---|
from |
String
|
The current path of the file or directory to be renamed. |
to |
String
|
The new path for the file or directory. |
Returns:
- Type:
-
Promise
(static) renameSync(from, to)
Renames oldPath to newPath synchronously.
Parameters:
Name | Type | Description |
---|---|---|
from |
String
|
The current path of the file or directory to be renamed. |
to |
String
|
The new path for the file or directory. |
(static) rm(path, optionsopt) → {Promise}
Removes files and directories asynchronously.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file or directory to be removed. |
|||||||||||||||||||||
options |
Object
|
<optional> |
Configuration options for the removal operation.
|
Returns:
- Type:
-
Promise
(static) rmSync(path, optionsopt)
Removes files and directories synchronously.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file or directory to be removed. |
|||||||||||||||||||||
options |
Object
|
<optional> |
Configuration options for the removal operation.
|
(static) rmdir(path, optionsopt) → {Promise}
Removes empty directories asynchronously.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the directory to be removed. |
||||||||||||||||
options |
Object
|
<optional> |
Configuration options for directory removal.
|
Returns:
- Type:
-
Promise
(static) rmdirSync(path, optionsopt)
Removes empty directories synchronously.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the directory to be removed. |
||||||||||||||||
options |
Object
|
<optional> |
Configuration options for directory removal.
|
(static) stat(path) → {Promise.<FileStats>}
Retrieves asynchronously statistics for the file.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The path of the file for which statistics are to be retrieved. |
Returns:
- Type:
-
Promise.<FileStats>
An object containing the statistics of the file.
(static) statSync(path) → {Object}
Retrieves synchronously statistics for the file.
Parameters:
Name | Type | Description |
---|---|---|
path |
String
|
The path of the file for which statistics are to be retrieved. |
Returns:
- Type:
-
Object
An object containing the statistics of the file.
(static) watch(path, optionsopt) → {FsWatcher}
Returns an async iterator that watches for changes over a path.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path to be monitored for changes. |
|||||||||
options |
Object
|
<optional> |
Configuration options for the file watcher.
|
Returns:
- Type:
-
FsWatcher
An instance of the FsWatcher
class.
(static) writeFile(path, data, optionsopt) → {Promise}
Writes asynchronously contents to a file.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file where the data is to be written. |
|||||||||
data |
String
|
Uint8Array
|
The data to write to the file. |
|||||||||
options |
String
|
Object
|
<optional> |
The options to control the file write operation.
|
Returns:
- Type:
-
Promise
(static) writeFileSync(path, data, optionsopt)
Writes synchronously contents to a file.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
path |
String
|
The path of the file where the data is to be written. |
|||||||||
data |
String
|
Uint8Array
|
The data to write to the file. |
|||||||||
options |
String
|
Object
|
<optional> |
The options to control the file write operation.
|
Type Definitions
FileStats
Information about a specific File
object.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
size |
number
|
The size of the file in bytes. |
|
atimeMs |
number
|
<optional> |
The timestamp indicating the last time this file was accessed (POSIX Epoch). |
mtimeMs |
number
|
<optional> |
The timestamp indicating the last time this file was modified (POSIX Epoch). |
birthtimeMs |
number
|
<optional> |
The timestamp indicating the creation time of this file (POSIX Epoch). |
isFile |
boolean
|
Returns |
|
isDirectory |
boolean
|
Returns |
|
isSymbolicLink |
boolean
|
Returns |
|
isSocket |
boolean
|
<optional> |
Returns |
isFIFO |
boolean
|
<optional> |
Returns |
isBlockDevice |
boolean
|
<optional> |
Returns |
isCharacterDevice |
boolean
|
<optional> |
Returns |
blocks |
number
|
<optional> |
The number of blocks allocated for this file. |
blksize |
number
|
<optional> |
The file system block size for i/o operations. |
mode |
number
|
<optional> |
A bit-field describing the file type and mode. |
dev |
number
|
<optional> |
The numeric identifier of the device containing the file. |
gid |
number
|
<optional> |
The numeric group identifier of the group that owns the file (POSIX). |
inode |
number
|
<optional> |
The file system specific "Inode" number for the file. |
nlink |
number
|
<optional> |
The number of hard-links that exist for the file. |
rdev |
number
|
<optional> |
A numeric device identifier if the file represents a device. |
Type:
-
Object