Getting File Info
Another common task is to get basic information about file system objects, such as file size, mode, modification time, whether the entry is a file or folder, etc. You can obtain such information by using one of the following calls:
fs.stat(path, callback)fs.statSync(path)
The fsStatSync()
method returns a Stats
object. The fs.stat()
method is executed, and the Stats
object is passed to the callback function as the second parameter. The first parameter is error
if an error occurs.
Table 6.2 lists some of the most commonly used attributes and methods attached to the Stats
object.
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.