stat() method provided by the fs module.
You call it passing a file path, and once Node.js gets the file details it will call the callback function you pass, with 2 parameters: an error message, and the file stats:
- ESM
- CJS
- ESM
- CJS
What information is available
The file information is included in thestats variable. A lot is available, including:
- Whether the file is a directory or a file, using
stats.isFile()andstats.isDirectory() - Whether the file is a symbolic link using
stats.isSymbolicLink() - The file size in bytes using
stats.size
- ESM
- CJS
Using the promise-based API
You can also use the promise-basedfsPromises.stat() method offered by the fs/promises module:
- ESM
- CJS
You can read more about the
fs module in the official documentation.