Node.js stats.dev Property
Last Updated :
08 Oct, 2021
Improve
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:
javascript
Output:
javascript
Output:
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:
// Node.js program to demonstrate the
// stats.dev Property
// Accessing fs module
const fs = require('fs');
// Calling fs.Stats stats.dev
// using stat for file
fs.stat('./filename.txt', (err, stats) => {
if (err) throw err;
console.log("using stat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
//using lstat for file
fs.lstat('./filename.txt', (err, stats) => {
if (err) throw err;
console.log("using lstat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
//using stat for directory
fs.stat('./', (err, stats) => {
if (err) throw err;
console.log("using stat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
//using lstat for directory
fs.lstat('./', (err, stats) => {
if (err) throw err;
console.log("using lstat: the numeric "
+ "identity of the device is "
+ stats.dev);
});
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 891323748Example 2:
// Node.js program to demonstrate the
// stats.dev Property
// Accessing fs module
const fs = require('fs').promises;
// Calling stats.dev property from
// fs.Stats class
(async () => {
const stats = await fs.stat(
'./fs_stat_dev.txt');
//using stat synchronous
console.log("The numeric identity "
+ "of the device is " + stats.dev);
})().catch(console.error)
The numeric identity of the device is 891323748Note: 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