Node.js stats.dev Property
The stats.dev 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 situated.
Syntax:
stats.dev;
Parameters: This property does not accept any parameter.
Return Value: It returns a number or BigInt value which represents the identity of the device in which the file is situated.
Below examples illustrate the use of stats.dev property in Node.js:
Example 1:
const fs = require( 'fs' );
fs.stat( './filename.txt' , (err, stats) => {
if (err) throw err;
console.log( "using stat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
fs.lstat( './filename.txt' , (err, stats) => {
if (err) throw err;
console.log( "using lstat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
fs.stat( './' , (err, stats) => {
if (err) throw err;
console.log( "using stat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
fs.lstat( './' , (err, stats) => {
if (err) throw err;
console.log( "using lstat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
|
Output:
using stat: the numeric identity of the device is 891323748
using lstat: the numeric identity of the device is 891323748
using stat: the numeric identity of the device is 891323748
using lstat: the numeric identity of the device is 891323748
Example 2:
const fs = require( 'fs' ).promises;
(async () => {
const stats = await fs.stat(
'./fs_stat_dev.txt' );
console.log( "The numeric identity "
+ "of the device is " + stats.dev);
})(). catch (console.error)
|
Output:
The numeric identity of the device is 891323748
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_dev
Last Updated :
08 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...