Node.js stats.ino Property
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:
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:
const fs = require( 'fs' );
fs.stat( './filename.txt' , (err, stats) => {
if (err) throw err;
console.log( "using stat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
fs.lstat( './filename.txt' , (err, stats) => {
if (err) throw err;
console.log( "using lstat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
fs.stat( './' , (err, stats) => {
if (err) throw err;
console.log( "using stat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
fs.lstat( './' , (err, stats) => {
if (err) throw err;
console.log( "using lstat: the \"Inode\" "
+ "number of the file is " + stats.ino);
});
|
Output:
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 14918173765820528
Example 2:
const fs = require( 'fs' ).promises;
(async() => {
const stats = await fs.stat( './filename.txt' );
console.log( "The \"Inode\" number "
+ "of the file is " +stats.ino);
})(). catch (console.error)
|
Output:
The "Inode" number of the file is 1125899907737972
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_ino
Last Updated :
07 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...