The
stats.nlink property is an inbuilt application programming interface of the fs.Stats class which is used to get the number of hard-links for the file.
Syntax:
stats.nlink;
Return Value: It returns a number or BigInt value which represents the number of hard-links for the file.
Below examples illustrate the use of stats.nlink property in Node.js:
Example 1:
Output:
using stat: number of hard-links for the file is 1
using lstat: number of hard-links for the file is 1
using stat: number of hard-links for the file is 1
using lstat: number of hard-links for the file is 1
Example 2:
Output:
(node:13780) ExperimentalWarning: The fs.promises API
is experimental
using stat synchronous: number of hard-links for the file is 1
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_nlink