Getting the stats of a file is quick and easy in node.js with just the nodejs built in core file system module fs.stat method. A stat object contains useful information about a file such as when it was last modified, and the data size of it. A stat object also contains methods that can be used to find if the current file is in fact a file, or a directory. So in this post I will be going over a few quick examples of using the fs.stat method in a nodejs environment.
For a basic example of fs.stat how about just getting the stats of a readme file in a demo folder. to do this I just need to require in the filesystem module, and then I can use the fs.stat method to get the stats of a file by passing the path to the file as the first argument, and then a callback as the second argument. In recent versions of nodejs version 12 and forward promises can be used as well, but for now I am using callbacks as a way to ensure better backward compatibility with older versions of node.