Package-level declarations
Types
A class representing a directory stream.
Instances of fs.ReadStream
are created and returned using the {@link createReadStream} function.
Provides information about a mounted file system.
Class: fs.StatWatcher
Watch for changes on filename
. The callback listener
will be called each time the file is accessed.
Instances of fs.WriteStream
are created and returned using the {@link createWriteStream} function.
Properties
Functions
Asynchronously tests a user's permissions for the file specified by path.
Tests a user's permissions for the file or directory specified by path
. The mode
argument is an optional integer that specifies the accessibility checks to be performed. mode
should be either the value fs.constants.F_OK
or a mask consisting of the bitwise OR of any of fs.constants.R_OK
, fs.constants.W_OK
, and fs.constants.X_OK
(e.g.fs.constants.W_OK | fs.constants.R_OK
). Check File access constants
for possible values of mode
.
Tests a user's permissions for the file or directory specified by path
. The mode
argument is an optional integer that specifies the accessibility checks to be performed. mode
should be either the value fs.constants.F_OK
or a mask consisting of the bitwise OR of any of fs.constants.R_OK
, fs.constants.W_OK
, and fs.constants.X_OK
(e.g.fs.constants.W_OK | fs.constants.R_OK
). Check File access constants
for possible values of mode
.
Synchronously tests a user's permissions for the file or directory specified by path
. The mode
argument is an optional integer that specifies the accessibility checks to be performed. mode
should be either the value fs.constants.F_OK
or a mask consisting of the bitwise OR of any of fs.constants.R_OK
, fs.constants.W_OK
, and fs.constants.X_OK
(e.g.fs.constants.W_OK | fs.constants.R_OK
). Check File access constants
for possible values of mode
.
Asynchronously append data to a file, creating the file if it does not yet exist. data
can be a string or a Buffer
.
Asynchronously append data to a file, creating the file if it does not exist.
Asynchronously append data to a file, creating the file if it does not yet exist. data
can be a string or a Buffer
.
Synchronously append data to a file, creating the file if it does not yet exist. data
can be a string or a Buffer
.
Changes the permissions of a file.
Closes the file descriptor. No arguments other than a possible exception are given to the completion callback.
Asynchronously copies src
to dest
. By default, dest
is overwritten if it already exists. No arguments other than a possible exception are given to the callback function. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.
Synchronously copies src
to dest
. By default, dest
is overwritten if it already exists. Returns undefined
. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.
Asynchronously copies the entire directory structure from src
to dest
, including subdirectories and files.
Asynchronously copies the entire directory structure from src
to dest
, including subdirectories and files.
Synchronously copies the entire directory structure from src
to dest
, including subdirectories and files.
Unlike the 16 KiB default highWaterMark
for a stream.Readable
, the stream returned by this method has a default highWaterMark
of 64 KiB.
options
may also include a start
option to allow writing data at some position past the beginning of the file, allowed values are in the \[0, Number.MAX_SAFE_INTEGER
\] range. Modifying a file rather than replacing it may require the flags
option to be set to r+
rather than the default w
. The encoding
can be any one of those accepted by Buffer
.
Returns true
if the path exists, false
otherwise.
Returns true
if the path exists, false
otherwise.
Sets the permissions on the file. No arguments other than a possible exception are given to the completion callback.
Sets the permissions on the file. Returns undefined
.
Sets the owner of the file. Returns undefined
.
Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX fdatasync(2)
documentation for details. No arguments other than a possible exception are given to the completion callback.
Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX fdatasync(2)
documentation for details. Returns undefined
.
Invokes the callback with the fs.Stats
for the file descriptor.
Retrieves the fs.Stats
for the file descriptor.
Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX fsync(2)
documentation for more detail. No arguments other than a possible exception are given to the completion callback.
Asynchronous ftruncate(2) - Truncate a file to a specified length.
Truncates the file descriptor. No arguments other than a possible exception are given to the completion callback.
Truncates the file descriptor. Returns undefined
.
Synchronous version of {@link futimes}. Returns undefined
.
Retrieves the files matching the specified pattern.
Retrieves the files matching the specified pattern.
Changes the permissions on a symbolic link.
Changes the permissions on a symbolic link. Returns undefined
.
Set the owner for the path. Returns undefined
.
Creates a new link from the existingPath
to the newPath
. See the POSIX link(2)
documentation for more detail. No arguments other than a possible exception are given to the completion callback.
Retrieves the fs.Stats
for the symbolic link referred to by the path. The callback gets two arguments (err, stats)
where stats
is a fs.Stats
object. lstat()
is identical to stat()
, except that if path
is a symbolic link, then the link itself is stat-ed, not the file that it refers to.
Equivalent to fsPromises.stat()
unless path
refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. Refer to the POSIX lstat(2)
document for more detail.
Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic link, then the link is not dereferenced: instead, the timestamps of the symbolic link itself are changed.
Changes the access and modification times of a file in the same way as fsPromises.utimes()
, with the difference that if the path refers to a symbolic link, then the link is not dereferenced: instead, the timestamps of the symbolic link itself are changed.
Change the file system timestamps of the symbolic link referenced by path
. Returns undefined
, or throws an exception when parameters are incorrect or the operation fails. This is the synchronous version of {@link lutimes}.
Asynchronous mkdir(2) - create a directory.
Asynchronous mkdir(2) - create a directory with a mode of 0o777
.
Asynchronously creates a directory.
Asynchronous mkdir(2) - create a directory.
Asynchronously creates a directory.
Synchronous mkdir(2) - create a directory.
Synchronously creates a directory. Returns undefined
, or if recursive
is true
, the first directory path created. This is the synchronous version of {@link mkdir}.
Asynchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
Creates a unique temporary directory. A unique directory name is generated by appending six random characters to the end of the provided prefix
. Due to platform inconsistencies, avoid trailing X
characters in prefix
. Some platforms, notably the BSDs, can return more than six random characters, and replace trailing X
characters in prefix
with random characters.
Creates a unique temporary directory.
Creates a unique temporary directory. A unique directory name is generated by appending six random characters to the end of the provided prefix
. Due to platform inconsistencies, avoid trailing X
characters in prefix
. Some platforms, notably the BSDs, can return more than six random characters, and replace trailing X
characters in prefix
with random characters.
Asynchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix
to create a unique temporary directory.
Synchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
Returns the created directory path.
Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be 0o666
.
Opens a FileHandle
.
Asynchronous file open. See the POSIX open(2)
documentation for more details.
Returns a Blob
whose data is backed by the given file.
Asynchronously open a directory. See the POSIX opendir(3)
documentation for more details.
Asynchronously open a directory for iterative scanning. See the POSIX opendir(3)
documentation for more detail.
Synchronously open a directory. See opendir(3)
.
Similar to the above fs.read
function, this version takes an optional options
object. If not otherwise specified in an options
object, buffer
defaults to Buffer.alloc(16384)
, offset
defaults to 0
, length
defaults to buffer.byteLength
, - offset
as of Node 17.6.0 position
defaults to null
Read data from the file specified by fd
.
Asynchronous readdir(3) - read a directory.
Reads the contents of a directory.
Reads the contents of a directory. The callback gets two arguments (err, files)
where files
is an array of the names of the files in the directory excluding '.'
and '..'
.
Reads the contents of a directory.
Asynchronous readdir(3) - read a directory.
Reads the contents of the directory.
Synchronous readdir(3) - read a directory.
Asynchronously reads the entire contents of a file.
Asynchronously reads the entire contents of a file.
Synchronously reads the entire contents of a file.
Returns the contents of the path
.
Asynchronous readlink(2) - read value of a symbolic link.
Reads the contents of the symbolic link referred to by path
. See the POSIX readlink(2)
documentation for more detail. The promise is fulfilled with thelinkString
upon success.
Reads the contents of the symbolic link referred to by path
. The callback gets two arguments (err, linkString)
.
Reads the contents of the symbolic link referred to by path
. See the POSIX readlink(2)
documentation for more detail. The promise is fulfilled with thelinkString
upon success.
Asynchronous readlink(2) - read value of a symbolic link.
Synchronous readlink(2) - read value of a symbolic link.
Returns the symbolic link's string value.
Similar to the above fs.readSync
function, this version takes an optional options
object. If no options
object is specified, it will default with the above values.
Returns the number of bytesRead
.
Read from a file specified by fd
and write to an array of ArrayBufferView
s using readv()
.
For detailed information, see the documentation of the asynchronous version of this API: {@link readv}.
Asynchronous realpath(3) - return the canonicalized absolute pathname.
Determines the actual location of path
using the same semantics as the fs.realpath.native()
function.
Asynchronously computes the canonical pathname by resolving .
, ..
, and symbolic links.
Determines the actual location of path
using the same semantics as the fs.realpath.native()
function.
Asynchronous realpath(3) - return the canonicalized absolute pathname.
Synchronous realpath(3) - return the canonicalized absolute pathname.
Returns the resolved pathname.
Asynchronously rename file at oldPath
to the pathname provided as newPath
. In the case that newPath
already exists, it will be overwritten. If there is a directory at newPath
, an error will be raised instead. No arguments other than a possible exception are given to the completion callback.
Renames oldPath
to newPath
.
Renames the file from oldPath
to newPath
. Returns undefined
.
Asynchronously removes files and directories (modeled on the standard POSIX rm
utility). No arguments other than a possible exception are given to the completion callback.
Asynchronous rmdir(2)
. No arguments other than a possible exception are given to the completion callback.
Removes the directory identified by path
.
Synchronous rmdir(2)
. Returns undefined
.
Asynchronous stat(2)
. The callback gets two arguments (err, stats)
wherestats
is an fs.Stats
object.
Asynchronous statfs(2)
. Returns information about the mounted file system which contains path
. The callback gets two arguments (err, stats)
where stats
is an fs.StatFs
object.
Synchronous statfs(2)
. Returns information about the mounted file system which contains path
.
Asynchronous symlink(2) - Create a new symbolic link to an existing file.
Creates the link called path
pointing to target
. No arguments other than a possible exception are given to the completion callback.
Returns undefined
.
Asynchronous truncate(2) - Truncate a file to a specified length.
Truncates the file. No arguments other than a possible exception are given to the completion callback. A file descriptor can also be passed as the first argument. In this case, fs.ftruncate()
is called.
Truncates (shortens or extends the length) of the content at path
to len
bytes.
Truncates the file. Returns undefined
. A file descriptor can also be passed as the first argument. In this case, fs.ftruncateSync()
is called.
If path
refers to a symbolic link, then the link is removed without affecting the file or directory to which that link refers. If the path
refers to a file path that is not a symbolic link, the file is deleted. See the POSIX unlink(2)
documentation for more detail.
Synchronous unlink(2)
. Returns undefined
.
Stop watching for changes on filename
. If listener
is specified, only that particular listener is removed. Otherwise, all listeners are removed, effectively stopping watching of filename
.
Returns undefined
.
Watch for changes on filename
, where filename
is either a file or a directory, returning an FSWatcher
.
Returns an async iterator that watches for changes on filename
, where filename
is either a file or a directory.
Watch for changes on filename
, where filename
is either a file or a directory.
Watch for changes on filename
. The callback listener
will be called each time the file is accessed.
Asynchronously writes buffer
to the file referenced by the supplied file descriptor.
Asynchronously writes string
to the file referenced by the supplied file descriptor.
Write buffer
to the file specified by fd
.
Asynchronously writes data to a file, replacing the file if it already exists. data
can be a string, a buffer, an AsyncIterable, or an Iterable object.
Asynchronously writes data to a file, replacing the file if it already exists.
When file
is a filename, asynchronously writes data to the file, replacing the file if it already exists. data
can be a string or a buffer.
Asynchronously writes data to a file, replacing the file if it already exists. data
can be a string, a buffer, an AsyncIterable, or an Iterable object.
Returns undefined
.
Synchronously writes string
to the file referenced by the supplied file descriptor, returning the number of bytes written.
For detailed information, see the documentation of the asynchronous version of this API: {@link write}.
Write an array of ArrayBufferView
s to the file specified by fd
using writev()
.
For detailed information, see the documentation of the asynchronous version of this API: {@link writev}.