Node.js stats.rdev Property from fs.Stats Class
Last Updated :
26 Jun, 2020
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:
const fs = require( 'fs' );
fs.stat( './filename.txt' , (err, stats) => {
if (err) throw err;
console.log( "using stat: numeric "
+ "identity of the device is "
+ stats.rdev);
});
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:
const fs = require( 'fs' ).promises;
(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
Share your thoughts in the comments
Please Login to comment...