Open In App

Node.js stats.dev Property

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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);
});


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:




// 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)


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
Previous
Next
Share your thoughts in the comments
Similar Reads