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