Open In App

Node.js stats.rdev Property from fs.Stats Class

Last Updated : 26 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The stats.rdev property is an inbuilt application programming interface of the fs.Stats class 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”.

Syntax:

stats.rdev;

Return Value: It returns a number or BigInt value that represents the identity of the device in which the file is stored in the file is considered to be “special”.

Below examples illustrate the use of stats.rdev property in Node.js:

Example 1:




// Node.js program to demonstrate the   
// stats.rdev property
  
// Accessing fs module
const fs = require('fs');
  
// Calling fs.Stats stats.rdev
// using stat
fs.stat('./filename.txt', (err, stats) => {
    if (err) throw err;
    console.log("using stat: numeric "
        + "identity of the device is " 
        + stats.rdev);
});
  
// Using lstat
fs.lstat('./filename.txt', (err, stats) => {
    if (err) throw err;
    console.log("using lstat: numeric "
        + "identity of the device is " 
        + stats.rdev);
});


Output:

using stat: numeric identity of the device is 0
using lstat: numeric identity of the device is 0

Example 2:




// Node.js program to demonstrate the   
// stats.rdev property
  
// Accessing fs module
const fs = require('fs').promises;
   
// Calling fs.Stats stats.rdev
(async() => {
    const stats = await fs.stat('./filename.txt');
  console.log("using stat synchronous: numeric "
    + "identity of the device is " + stats.rdev);
})().catch(console.error)


Output:

(node:1656) ExperimentalWarning: The fs.promises API 
is experimental 
using stat synchronous: numeric identity of the device is 0

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_rdev



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads