Open In App

Node.js stats.isBlockDevice() Method from fs.Stats Class

Last Updated : 13 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The stats.isBlockDevice() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object is of a block device or not.

Syntax:

stats.isBlockDevice();

Parameters: This method does not accept any parameter.

Return Value: This method returns a boolean value, i.e. true if fs.Stats object describes a block device, false otherwise.

Below examples illustrate the use of stats.isBlockDevice() method in Node.js:

Example 1:




// Node.js program to demonstrate the 
// stats.isBlockDevice() method
  
// Accessing fs module
const fs = require('fs');
  
// Calling fs.Stats isBlockDevice()
fs.stat('./filename.txt', (err, stats) => {
    if (err) throw err;
  
    // console.log(`stats: ${JSON.stringify(stats)}`);
    console.log(stats.isBlockDevice());
});


Output:

false

Example 2:




// Node.js program to demonstrate the 
// stats.isBlockDevice() method
  
// Accessing fs module
const fs = require('fs');
  
// Calling fs.Stats isBlockDevice() method
fs.stat('./filename.txt', (err, stats) => {
    if (err) throw err;
  
    // console.log(
    //  `stats: ${JSON.stringify(stats)}`);
    if (stats.isBlockDevice()) {
        console.log("fs.Stats describes a "
            + "block device");
    } else {
        console.log("fs.Stats does not "
            + "describe a block device");
    }
});


Output:

fs.Stats does not describe a block device

Note: The above program will compile and run by using the node filename.js command and use the file_path correctly.

Reference: https://nodejs.org/api/fs.html#fs_stats_isblockdevice



Previous Article
Next Article

Similar Reads

Node.js fs.Dirent.isBlockDevice() Method
The fs.Dirent.isBlockDevice() method is an inbuilt application programming interface of class fs.Dirent within File System module which is used to check if the particular dirent describes a block device or not. Syntax: const dirent.isBlockDevice() Parameters: This method does not accept any parameter. Return Value: This method returns true if the p
2 min read
Node.js stats.isDirectory() Method from fs.Stats Class
The stats.isDirectory() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a file system directory or not. Syntax: stats.isDirectory(); Parameters: This method does not accept any parameters. Return: This method returns a boolean value, which is true if fs.Stats obje
2 min read
Node.js stats.isCharacterDevice() Method from fs.Stats Class
The 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. Syntax: stats.isCharacterDevice(); Parameters: This method does not accept any parameter. Return Value: This method returns a boolean value, which is true if fs.St
1 min read
Node.js stats.isFile() Method from fs.Stats Class
The 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. Syntax: stats.isFile(); Parameters: This method does not accept any parameters. Return Value: This method returns a boolean value, which is true if fs.Stats object describes a file,
2 min read
Node.js stats.atimeMs Property from fs.Stats Class
The stats.atimeMs property 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 milliseconds. Syntax: stats.atimeMs; Parameters: This property does not use any parameters. Return Value: It returns a number or BigInt value that repres
2 min read
Node.js stats.mtimeMs Property from fs.Stats Class
The stats.mtimeMs 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 since the POSIX epoch expressed in milliseconds. Syntax: stats.mtimeMs; Parameters: This property does not accept any parameters. Return Value: It returns a number or BigInt value that rep
2 min read
Node.js stats.mode Property from fs.Stats Class
The 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. Syntax: stats.mode; Return Value: It returns a number or BigInt value that represents a bit-field that describes the file type and mode. Below examples illustrate the use of stats.mode in Node.js: E
2 min read
Node.js stats.nlink Property from fs.Stats Class
The 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. Syntax: stats.nlink; Return Value: It returns a number or BigInt value which represents the number of hard-links for the file. Below examples illustrate the use of stats.nlink property in Node.js
2 min read
Node.js stats.uid Property from fs.Stats Class
The 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. Syntax: stats.uid; Return Value: It returns a number or BigInt value which represents the identity of the user that owns the file. Below examples illustrate the
2 min read
Node.js stats.gid Property from fs.Stats Class
The stats.gid property is an inbuilt application programming interface of the fs.Stats class which is used to get the numeric (number / bigint) identity of the group to which the file belongs to. Syntax: stats.gid; Return Value: It returns a number or BigInt value which represents the identity of the group that owns the file. Below examples illustr
2 min read