The stats.ino property is an inbuilt application programming interface of the fs.Stats class is used to get the "Inode" number of the file specified by the file system.
Syntax:
javascript
Output:
javascript
Output:
stats.ino;Parameters: This property does not have any parameter. Return Value: It returns a number or BigInt value which represents the "Inode" number of the file specified by the file system. Below examples illustrate the use of stats.ino property in Node.js: Example 1:
// Node.js program to demonstrate the
// stats.ino Property
// Accessing fs module
const fs = require('fs');
// Calling stats.ino property from
// fs.Stats class
// For files using stat
fs.stat('./filename.txt', (err, stats) => {
if (err) throw err;
console.log("using stat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
// Using lstat
fs.lstat('./filename.txt', (err, stats) => {
if (err) throw err;
console.log("using lstat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
// For directories using stat
fs.stat('./', (err, stats) => {
if (err) throw err;
console.log("using stat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
//using lstat
fs.lstat('./', (err, stats) => {
if (err) throw err;
console.log("using lstat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
using stat: the "Inode" number of the file is 1125899907737972 using lstat: the "Inode" number of the file is 1125899907737972 using stat: the "Inode" number of the file is 14918173765820528 using lstat: the "Inode" number of the file is 14918173765820528Example 2:
// Node.js program to demonstrate the
// stats.ino Property
// Accessing fs module
const fs = require('fs').promises;
// Calling stats.ino property from
// fs.Stats class
(async() => {
const stats = await fs.stat('./filename.txt');
// Using stat synchronous
console.log("The \"Inode\" number "
+ "of the file is "+stats.ino);
})().catch(console.error)
The "Inode" number of the file is 1125899907737972Note: 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_ino