Asynchronous vs Synchronous Methods

The fs module offers both asynchronous and synchronous methods. Asynchronous methods are non-blocking and typically use callbacks or Promises for handling operations, while synchronous methods block the execution until the operation completes.

Example: Below is an example of a NodeJS file System.

Javascript

    // Node.js program to demonstrate the
    // fsPromises.opendir() method

    // Import the filesystem module
    const fs = require('fs');
    const fsPromises = fs.promises;

    fsPromises.opendir(__dirname)
        .then(function(result) {
            console.log(result);
        })
        .catch(function(error) {
            console.log(error);
        });

Output:

Dir {
[Symbol(kDirHandle)]: DirHandle {},
[Symbol(kDirBufferedEntries)]: [],
[Symbol(kDirPath)]: 'C:\\Users\\Lenovo\\Downloads\\Internship\\Program',
[Symbol(kDirClosed)]: false,
[Symbol(kDirOptions)]: { bufferSize: 32, encoding: 'utf8' },
[Symbol(kDirReadPromisified)]: [Function: bound [kDirReadImpl]],
[Symbol(kDirClosePromisified)]: [Function: bound close]
}

The Complete NodeJS File System are listed below:

Node.js File System

Description

Node.js fs.readFile() MethodThis method read the entire file into buffer. To load the fs module we use require() method.
Node.js fs.exists() MethodThe fs.exists() method is used to test whether the given path exists or not in the file system.
Node.js fs.existsSync() MethodThe fs.existsSync() method is used to synchronously check if a file already exists in the given path or not.
Node.js fs.mkdir() MethodThe fs.mkdir() method i Node.js is used to create a directory asynchronously.
Node.js fs.truncate() MethodThe fs.truncate() method in node.js is used to change the size of the file i.e either increase or decrease the file size. 
Node.js fs.renameSync() MethodThe fs.renameSync() method is used to synchronously rename a file at the given old path to the given new path.
Node.js fs.rmdir() MethodThe fs.rmdir() method is used to delete a directory at the given path.
Node.js fs.stat() MethodThe fs.stat() method is used to return information about the given file or directory. 
Node.js fs.mkdtempSync() MethodThe fs.mkdtempSync() method is an inbuilt application programming interface of fs module
Node.js fs.realpath() MethodThe fs.realPath() method is used to compute the canonical pathname of the given path.
Node.js fs.open() MethodThis is used. fs.readFile() is only for reading the file and similarly fs.writeFile() 
Node.js fs.mkdirSync() MethodThis is an inbuilt application programming interface of fs module which provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions.
Node.js fs.statSync() MethodThe fs.statSync() method is used to synchronously return information about the given file path.
Node.js fs.write() MethodThe fs.write() method is an inbuilt application programming interface of fs module which is used to specify the position
Node.js fs.createReadStream() MethodThis is an inbuilt application programming interface of fs module which allow you to open up a file/stream and read the data present in it.
Node.js fs.openSync() MethodThis is an inbuilt application programming interface of fs module which is used to return an integer value that represents the file descriptor.
Node.js fs.rmdirSync() MethodThe fs.rmdirSync() method is used to synchronously delete a directory at the given path.
Node.js fs.ftruncate() MethodThe fs.ftruncate() method is used to change the size of the file i.e. either increase or decrease the file size.
Node.js fs.truncateSync() MethodThe fs.truncateSync() method is used to synchronously change the size of the file 
Node.js fs.readdir() MethodThe fs.readdir() method is used to asynchronously read the contents of a given directory.
Node.js fs.writeFileSync() MethodThe ‘fs’ module of Node.js implements the File I/O operation. Methods in the fs module can be synchronous as well as asynchronous.
Node.js fs.readFileSync() MethodThe fs.readFileSync() method is an inbuilt application programming interface of fs module which is used to read the file and return its content.
Node.js fs.lstat() MethodThe fs.lstat() method is similar to the fs.stat() method except that it is used to return
Node.js fs.symlinkSync() MethodThe fs.symlinkSync() method is used to synchronously create a symlink to the specified path.
Node.js fs.realpathSync() MethodThe fs.realpathSync() method is used to synchronously compute the canonical pathname of a given path.
Node.js fs.fstat() MethodThe fs.fstat() method is used to return information about the given file descriptor. 
Node.js fs.mkdtemp() MethodThe fs.mkdtemp() method is used to create a unique temporary directory.
Node.js fs.lstatSync() MethodThis  is used to synchronously return information about the symbolic link that is being used to refer to a file or directory.
Node.js fs.readdirSync() Me thod This is used to synchronously read the contents of a given directory.
Node.js fs.writeFile() MethodThe fs.writeFile() method is used to asynchronously write the specified data to a file.
Node.js fs.fstatSync() MethodThe fs.fstatSync() method is used to synchronously return information about the given file descriptor.
Node.js fs.copyFileSync() FunctionThis  is used to synchronously copy a file from the source path to destination path. 
Node.js fs. lchown() Methodfs.chownSync() method which does dereference the links to their path.
Node.js fs. lchownSync() Methodfs.chownSync() method which does dereference the links to their path.
Node.js fs.closeSync() Methodfs.closeSync() on a file descriptor while some other operation is being performed on it may lead to undefined behavior.
Node.js fs.close() MethodThis is used to asynchronously close the given file descriptor thereby clearing the file that is associated with it.
Node.js fs.fchmod() MethodThe fs.fchmod() method is used to change the permissions of a given file descriptor.
Node.js fs.link() MethodThe fs.link() method is used to create a hard link to the given path.
Node.js fs.symlink() FunctionThe fs.symlink() method is used to create a symlink to the specified path.
Node.js fs.unlinkSync() MethodThe fs.unlinkSync() method is used to synchronously remove a file or symbolic link from the filesystem.
Node.js fs.chmodSync() MethodThe fs.chmodSync() method is used to synchronously change the permissions of a given path.
Node.js fs.chmod() MethodThese permissions can be specified using string constants or octal numbers that correspond to their respective file modes.
Node.js fs.unlink() MethodThe fs.unlink() method is used to remove a file or symbolic link from the filesystem. 
Node.js fs.fchmodSync() MethodThe fs.fchmodSync() method is an inbuilt application programming of fs module which is used to synchronously change the permissions of a given file descriptor.
Node.js fs.readlinkSync() MethodThis  is used to synchronously return a symbolic link’s value, i.e. the path it is linked to.
Node.js fs. linksync() MethodThe hard link created would still point to the same file even if the file is renamed. 
Node.js fs.futimesSync() Method This is used to synchronously change the modification and access timestamps of given file descriptor. T
Node.js fs.utimesSync() MethodThe fs.utimesSync() method is used to synchronously change the modification and access timestamps of a file. 
Node.js fs.utimes() MethodThe fs.utimes() method is used to asynchronously change the modification and access timestamps of a file.
Node.js fs.opendirSync() MethodThe fs.opendirSync() method is used to synchronously open a directory in the file system.
Node.js fs.opendir() Method It creates an fs.Dir object that is used to represent the directory.
Node.js fs.appendFile() FunctionThe fs.appendFile() method is used to asynchronously append the given data to a file. A new file is created if it does not exist. 
Node.js fs.chown() MethodThe fs.chown() method is used to asynchronously change the owner and group of the given path.
Node.js fs.fchown() FunctionThe fs.fchown() method is used to change the owner and group of the given file descriptor. 
Node.js fs.copyFile() FunctionThe fs.copyFile() method is used to asynchronously copy a file from the source path to destination path.
Node.js fs.appendFileSync() FunctionA new file is created if it does not exist. The optional options parameter can be used to modify the behavior of the operation.
Node.js fs. fchownSync() Method The function accepts a user id and group id that can be used to set the respective owner and group. It does not return anything.
Node.js fs.chownSync() MethodThe fs.chownSync() method is used to synchronously change the owner and group of the given path.
Node.js fs.accessSync() MethodThe fs.accessSync() method is used to synchronously test the permissions of a given file or directory. 
Node.js fs.access() MethodThe permissions to be checked can be specified as a parameter using file access constants.
Node.js fs.watchFile() MethodThe fs.watchFile() method is used to continuously watch for changes on the given file.
Node.js fsPromises.mkdtemp() MethodThe fsPromises.mkdtemp() method is an inbuilt method which creates a unique temporary directory and resolves the Promise with the created directory path.
Node.js fsPromises.chmod() MethodThe fsPromises.chmod() method is used to change the permissions of a given path. 
Node.js fs.unwatchFile() MethodThe fs.unwatchFile() method is used to stop watching for changes on the given file. 
Node.js fsPromises.open() MethodThe fsPromises.open() method is used to asynchronously open a file that returns a Promise that, when resolved, yields a FileHandle object.
Node.js fsPromises.mkdir() MethodThis is used to asynchronously create a directory then resolves the Promise with either no arguments, or the first directory path created if recursive is true.
Node.js fs.promise.readdir() MethodThe fs.promise.readdir() method defined in the File System module of Node.js.
Node.js fsPromises.appendFile() FunctionThe fsPromises.appendFile() method is used to asynchronously append the given data to a file.
Node.js fsPromise.lstat() MethodThe fs.promise.lstat() method is defined in the File System module of Node.js.
Node.js fsPromises.stat() MethodThe fsPromises.stat() method is used to return information about the given file or directory.
Node.js fsPromises.realpath() MethodThe fsPromises.realPath() method determines the actual location of path using the same semantics as the fs.realpath.native() function
Node.js fs.read() MethodNode.js is used for server-side scripting. Reading and writing files are the two most important operations that are performed in any application.
Node.js fsPromises.chown() MethodThe fsPromises.chown() method is used to change the ownership of a file then resolves the Promise with no arguments upon success.
Node.js fs.createWriteStream() MethodThis is an inbuilt application programming interface of fs module which allows to quickly make a writable stream for the purpose of writing data to a file. 
Node.js fs.futimes() MethodThe fs.futimes() method is used to asynchronously change the modification and access timestamps of given file descriptor.
Node.js fsPromises.truncate() MethodThe fsPromises.truncate() method is defined in the File System module of Node.js.
Node.js fsPromises.symlink() MethodThe fsPromises.symlink() method is used to create a symlink to the specified path then resolves the Promise with no arguments upon success. 
Node.js fsPromises.lchmod() MethodThe fsPromises.lchmod() method is used to change the permissions of a given path.
Node.js fsPromises.lchown() MethodThe fsPromises.lchown() method is used to change the ownership of a file then resolves the Promise with no arguments upon success
Node.js fsPromises.truncate() MethodThe fsPromises.truncate() method in node.js is used to change the size of the file i.e. either increase or decrease the file size.
Node.js fsPromises.opendir() MethodThe fsPromises.opendir() method is used to asynchronously open a directory in the file system.
Node.js fsPromises.utimes() MethodThe fsPromises.utimes() method is used to asynchronously change the modification and access timestamps of a file. 
Node.js fsPromises.copyFile() MethodThe fsPromises.copyFile() method is used to asynchronously copy a file from the source path to destination path. 
Node.js fsPromises.rename() MethodThe fsPromises.rename() method is used to asynchronously rename a file at the given old path to a given new path. 
Node.js fs.promises.appendFile() MethodThe fs.promises.appendFile() method of File System module in Node.js is used to interact with the hard disk of the user’s computer.
Node.js fsPromises.rmdir() MethodThe fsPromises.rmdir() method is used to delete a directory at the given path. It can also be used recursively to remove nested directories. 
Node.js fsPromises.writeFile() MethodThe fsPromises.writeFile() method is used to asynchronously write the specified data to a file. By default, the file would be replaced if it exists.
Node.js fsPromises.readFile() MethodThe fsPromises.readFile() method is used to read the file. This method read the entire file into buffer.
Node.js fsPromises.access() MethodThe fsPromises.access() method is used to test the permissions of a given file or directory specified by path. 
Node.js stats.ino PropertyThe stats.ino property is an inbuilt application programming interface of the fs.Stats class is used to get the “Inode” number of the file specified by the file system.
Node.js stats.birthtimeNs PropertyThis is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is created since the POSIX epoch expressed in milliseconds.
Node.js stats.atimeNs PropertyThis is  an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is accessed last time since the POSIX epoch expressed in nanoseconds.
Node.js fsPromises.opendir() Method The File System module is basically to interact with the hard disk of the user’s computer. The method is used to asynchronously open a directory.
Node.js stats.mtimeNs PropertyThe stats.mtimeNs property is an inbuilt application programming interface of the fs.
Node.js stats.isFIFO() MethodThis  is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a first-in-first-out (FIFO) pipe or not.
Node.js stats.isSymbolicLink() MethodThis is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a symbolic link or not.
Node.js stat.isSocket() MethodThe stats.isSocket() method is an inbuilt application programming interface of the fs.
Node.js stats.dev PropertyThe stats.dev property is an inbuilt application programming interface of the fs.
Node.js stats.mtime PropertyThe stats.mtime property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is modified last time.
Node.js filehandle.readFile() MethodThe filehandle.readFile() method is used to asynchronously read the file contents. This method reads the entire file into the buffer. It Asynchronously reads the entire contents of a file.
Node.js stats.ctimeNs PropertyThe stats.ctimeNs property is an inbuilt application programming interface of the fs.
Node.js stats.atime PropertyThis used to get the time and date when the file is accessed last time.
Node.js stats.birthtime PropertyThis is used to get the timestamp when the file is created.
Node.js stats.ctime PropertyThe stats.ctime property is an inbuilt application programming interface of the fs.
Node.js stats.ctimeMs Property from fs.Stats ClassThe stats.ctimeMs property is an inbuilt application programming interface of the fs.
Node.js stats.mtimeMs Property from fs.Stats ClassThe stats.mtimeMs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp 
Node.js stats.blocks Property from fs.Stats ClassThe stats.blocks property is an inbuilt application programming interface of the fs.Stats class is used to get the number of blocks allocated for the file.
Node.js stats.isCharacterDevice() Method from fs.Stats ClassThe stats.isCharacterDevice() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object is of a character device or not.
Node.js stats.atimeMs Property from fs.Stats ClassThe stats.atimeMs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp 
Node.js stats.birthtimeMs Property from fs.Stats ClassThis is used to get the timestamp when the file is created since the POSIX epoch expressed in milliseconds.
Node.js filehandle.stat() Method from class: FileHandleThe File System module is basically to interact with the hard disk of the user’s computers. 
Node.js stats.blksize Property from fs.Stats ClassThe stats.blksize property is an inbuilt application programming interface of the fs.Stats class is used to get the block size for I/O operations in the file system in bytes.
Node.js stats.size Property from fs.Stats ClassThe stats.size property is an inbuilt application programming interface of the fs.Stats class is used to get the size of the file in bytes.
Node.js stats.nlink Property from fs.Stats ClassThe stats.nlink property is an inbuilt application programming interface of the fs.Stats class which is used to get the number of hard-links for the file.
Node.js stats.mode Property from fs.Stats ClassThe stats.mode property is an inbuilt application programming interface of the fs.Stats class which is used to get the file type and mode as bit-field.
Node.js stats.isFile() Method from fs.Stats ClassThe stats.isFile() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a file or not.
Node.js stats.gid Property from fs.Stats ClassThis is used to get the numeric (number / bigint) identity of the group to which the file belongs to.
Node.js stats.uid Property from fs.Stats ClassThe stats.uid property is an inbuilt application programming interface of the fs.Stats class is used to get the numeric (number / bigint) identity of the user to which the file belongs to.
Node.js stats.rdev Property from fs.Stats ClassThis  is used to get the numeric (number / bigint) identity of the device in which the file is stored in the file is considered to be “special”.
Node.js fs.filehandle.utimes() MethodThe fs.filehandle.utimes() method is an inbuilt application programming interface of class fs.filehandle within File System
Node.js fs.filehandle.truncate() MethodThis is used to truncate the particular file object and only that much byte will be retained which passed as an integer in truncate() method.
Node.js fs.Dirent.isFIFO() MethodThis is used to check if the particular dirent describes a first in first out pipe or not.
Node.js fs.filehandle.fd() MethodThis is used to provide the numeric file descriptor of this file handle object.
Node.js fs.Dirent.isSocket() MethodThis is used to check if the particular dirent describes a Socket or not.
Node.js fs.Dirent.isFile() MethodThis is used to check if the particular dirent describes a File or not.
Node.js fs.filehandle.write() MethodThis is an inbuilt application programming interface of class fs.filehandle within File System module which is used to write the data form the buffer to that particular file.
Node.js fs.Dir.close() MethodThis  is used to close the directory’s underlying resource handle asynchronously.
Node.js fs.Dirent.isCharacterDevice() MethodThis is used to check if the particular dirent describes a character device or not.
Node.js fs.Dir.read() MethodThis is used to read the each next directory (dirent) one by one asynchronously.
Node.js fs.Dirent.isBlockDevice() MethodThis is used to check if the particular dirent describes a block device or not.
Node.js filehandle.close() MethodThis is used to asynchronously close the given file descriptor thereby clearing the file that is associated with it.
Node.js filehandle.read() MethodIn order to read files without file descriptor the readFile() method of the filehandle package can be used.
Node.js stats.isDirectory() Method from fs.Stats ClassThis is used to check whether fs.Stats object describes a file system directory or not.
Node.js filehandle.writeFile() Method from class: FileHandleThis is used to defined in the File System module of Node.js. The File System module is basically to interact with the hard disk of the user’s computer.
Node.js fs.Dir.path() MethodThis is used to defined in the File System module of Node.js. The File System module is basically to interact with the hard disk of the user’s computer.
Node.js fs.filehandle.datasync() Methodfs.filehandle within File System module which is used to sync the data of the file.
Node.js fs.filehandle.chmod() Methodfs.filehandle within File System module which is used to change the permission of the particular file.
Node.js stats.isBlockDevice() Method from fs.Stats ClassThis  is used to check whether fs.Stats object is of a block device or not.
Node.js fs.filehandle.chown() MethodThis is used to change the ownership of the particular file.
Node.js fs.filehandle.sync() Methodfs.filehandle within File System module which is used to synchronize this file’s in-core state with the storage device.
Node.js filehandle.truncate() MethodThe truncate() method used to modify the inner contents of the file by ‘len’ bytes.
Node.js fs.dirent.name PropertyThe fs.Dirent.name property is an inbuilt application programming interface of class fs.Dirent
Node.js filehandle.appendFile() MethodThe File System module is basically to interact with the hard disk of the user’s computer. 
Node.js fs.Dirent.isDirectory() MethodThis is used to check if the particular dirent describes a Directory or not.
Node.js fs.Dirent.isSymbolicLink() MethodThis is used to check if the particular dirent describes a SymbolicLink or not.
Node.js fs.Dir.readSync() Methodfs.Dir within File System module which is used to read the each next dirent of directory.
Node.js fs.Dir.closeSync() MethodThis is used to close the directory’s underlying resource handle synchronously.
Node.js fs.promises.link() MethodThe fs.promises.link() method is an inbuilt application programming interface of the fs.promises class which is used to make a new name for a file.
Node.js fs.watch() Methodfs module which is used to continuously watch for changes in the given file or directory.
Node.js fs.readlink() MethodThe fs.readlink() method is an inbuilt application programming interface of fs module which is used to asynchronously return a symbolic link’s value.
Node.js fs.fdatasync() MethodThe fs.fdatasync() (Added in v0.1.96) method is an inbuilt application programming interface of the fs module which is similar to fs.fsync()
Node.js fs.fsync() MethodIt has both synchronous and asynchronous forms. The asynchronous form always takes a completion callback as its last argument.
Node.js fs.rmSync() MethodThe fs.rmSync() method is used to synchronously delete a file at the given path.
Node.js fs.rm() MethodThe fs.rm() method is used to delete a file at the given path. It can also be used recursively to remove directories.
Node.js fs.writeSync() Method This is used to work with files on the computer. The functions of the module can be used by importing the fs module.


Node.js File System Complete Reference

Node.js File System module is used to handle file operations like creating, reading, deleting, etc. Node.js provides an inbuilt module called FS (File System). Node.js gives the functionality of file I/O by providing wrappers around the standard POSIX functions. All file system operations can have synchronous and asynchronous forms depending on user requirements

Similar Reads

Asynchronous vs Synchronous Methods

The fs module offers both asynchronous and synchronous methods. Asynchronous methods are non-blocking and typically use callbacks or Promises for handling operations, while synchronous methods block the execution until the operation completes....