Node.js module

fs

The 'node:fs' module provides file system I/O operations, including reading, writing, renaming, and deleting files and directories. It offers both synchronous and asynchronous methods.

Fully supported in Bun

Fully implemented. 92% of Node.js's test suite passes.

Functions 88

  • fs.access()

    Tests a user's permissions for the file or directory specified by path.

  • fs.accessSync()

    Synchronously tests a user's permissions for the file or directory specified by path.

  • fs.appendFile()

    Asynchronously append data to a file, creating the file if it does not yet exist.

  • fs.appendFileSync()

    Synchronously append data to a file, creating the file if it does not yet exist.

  • fs.chmod()

    Asynchronously changes the permissions of a file.

  • fs.chmodSync()

    For detailed information, see the documentation of the asynchronous version of this API: chmod.

  • fs.chown()

    Asynchronously changes owner and group of a file.

  • fs.chownSync()

    Synchronously changes owner and group of a file.

  • fs.close()

    Closes the file descriptor.

  • fs.closeSync()

    Closes the file descriptor.

  • fs.copyFile()

    Asynchronously copies src to dest.

  • fs.copyFileSync()

    Synchronously copies src to dest.

  • fs.cp()

    Asynchronously copies the entire directory structure from src to dest, including subdirectories and files.

  • fs.cpSync()

    Synchronously copies the entire directory structure from src to dest, including subdirectories and files.

  • fs.createReadStream()

    options can include start and end values to read a range of bytes from the file instead of the entire file.

  • fs.createWriteStream()

    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_INTE…

  • fs.fchmod()

    Sets the permissions on the file.

  • fs.fchmodSync()

    Sets the permissions on the file.

  • fs.fchown()

    Sets the owner of the file.

  • fs.fchownSync()

    Sets the owner of the file.

  • fs.fdatasync()

    Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state.

  • fs.fdatasyncSync()

    Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state.

  • fs.fstat()

    Invokes the callback with the fs.Stats for the file descriptor.

  • fs.fstatSync()

    Retrieves the fs.Stats for the file descriptor.

  • fs.fsync()

    Request that all data for the open file descriptor is flushed to the storage device.

  • fs.fsyncSync()

    Request that all data for the open file descriptor is flushed to the storage device.

  • fs.ftruncate()

    Truncates the file descriptor.

  • fs.ftruncateSync()

    Truncates the file descriptor.

  • fs.futimes()

    Change the file system timestamps of the object referenced by the supplied file descriptor.

  • fs.futimesSync()

    Synchronous version of futimes.

  • fs.glob()

    Retrieves the files matching the specified pattern.

  • fs.globSync()

    When followSymlinks is enabled, detected symbolic link cycles are not traversed recursively.

  • fs.lchown()

    Set the owner of the symbolic link.

  • fs.lchownSync()

    Set the owner for the path.

  • fs.link()

    Creates a new link from the existingPath to the newPath.

  • fs.linkSync()

    Creates a new link from the existingPath to the newPath.

  • fs.lstat()

    Retrieves the fs.Stats for the symbolic link referred to by the path.

  • fs.lstatSync()

    Synchronous lstat(2) - Get file status.

  • fs.lutimes()

    Changes the access and modification times of a file in the same way as utimes, with the difference that if the path refers to a symbolic link, then the link is not der…

  • fs.lutimesSync()

    Change the file system timestamps of the symbolic link referenced by path.

  • fs.mkdir()

    Asynchronously creates a directory.

  • fs.mkdirSync()

    Synchronously creates a directory.

  • fs.mkdtemp()

    Creates a unique temporary directory.

  • fs.mkdtempDisposableSync()

    Returns a disposable object whose path property holds the created directory path.

  • fs.mkdtempSync()

    Returns the created directory path.

  • fs.open()

    Asynchronous file open.

  • fs.openAsBlob()

    Returns a Blob whose data is backed by the given file.

  • fs.opendir()

    Asynchronously open a directory.

  • fs.opendirSync()

    Synchronously open a directory.

  • fs.openSync()

    Returns an integer representing the file descriptor.

  • fs.read()

    Read data from the file specified by fd.

  • fs.readdir()

    Reads the contents of a directory.

  • fs.readdirSync()

    Reads the contents of the directory.

  • fs.readFile()

    Asynchronously reads the entire contents of a file.

  • fs.readFileSync()

    Returns the contents of the path.

  • fs.readlink()

    Reads the contents of the symbolic link referred to by path.

  • fs.readlinkSync()

    Returns the symbolic link's string value.

  • fs.readSync()

    Returns the number of bytesRead.

  • fs.readv()

    Read from a file specified by fd and write to an array of ArrayBufferViews using readv().

  • fs.readvSync()

    For detailed information, see the documentation of the asynchronous version of this API: readv.

  • fs.realpath()

    Asynchronously computes the canonical pathname by resolving ., .., and symbolic links.

  • fs.realpathSync()

    Returns the resolved pathname.

  • fs.rename()

    Asynchronously rename file at oldPath to the pathname provided as newPath.

  • fs.renameSync()

    Renames the file from oldPath to newPath.

  • fs.rm()

    Asynchronously removes files and directories (modeled on the standard POSIX rm utility).

  • fs.rmdir()

    Asynchronous rmdir(2).

  • fs.rmdirSync()

    Synchronous rmdir(2).

  • fs.rmSync()

    Synchronously removes files and directories (modeled on the standard POSIX rm utility).

  • fs.stat()

    Asynchronous stat(2).

  • fs.statfs()

    Asynchronous statfs(2).

  • fs.statfsSync()

    Synchronous statfs(2).

  • fs.statSync()

    Synchronous stat(2) - Get file status.

  • fs.symlink()

    Creates the link called path pointing to target.

  • fs.symlinkSync()

    Returns undefined.

  • fs.truncate()

    Asynchronous truncate(2) - Truncate a file to a specified length.

  • fs.unlink()

    Asynchronously removes a file or symbolic link.

  • fs.unlinkSync()

    Synchronous unlink(2).

  • fs.unwatchFile()

    Stop watching for changes on filename.

  • fs.utimes()

    Change the file system timestamps of the object referenced by path.

  • fs.utimesSync()

    Returns undefined.

  • fs.watch()

    Watch for changes on filename, where filename is either a file or a directory.

  • fs.watchFile()

    Watch for changes on filename.

  • fs.write()

    Write buffer to the file specified by fd.

  • fs.writeFile()

    When file is a filename, asynchronously writes data to the file, replacing the file if it already exists.

  • fs.writeFileSync()

    Returns undefined.

  • fs.writeSync()

    For detailed information, see the documentation of the asynchronous version of this API: write.

  • fs.writev()

    Write an array of ArrayBufferViews to the file specified by fd using writev().

  • fs.writevSync()

    For detailed information, see the documentation of the asynchronous version of this API: writev.

Classes 7

  • class fs.Dir

    A class representing a directory stream.

  • class fs.Dirent

    A representation of a directory entry, which can be a file or a subdirectory within the directory, as returned by reading from an fs.Dir.

  • class fs.ReadStream

    Instances of fs.ReadStream cannot be constructed directly.

  • class fs.Stats

    A fs.Stats object provides information about a file.

  • class fs.StatsFs

    Provides information about a mounted file system.

  • class fs.Utf8Stream

    An optimized UTF-8 stream writer that allows for flushing all the internal buffering on demand.

  • class fs.WriteStream

    Instances of fs.WriteStream cannot be constructed directly.

Interfaces 40

Types 15

Namespaces 41

Other 1