Asynchronous stat(2). The callback gets two arguments (err, stats) wherestats is an fs.Stats object.
In case of an error, the err.code will be one of Common System Errors.
Using fs.stat() to check for the existence of a file before callingfs.open(), fs.readFile() or fs.writeFile() is not recommended.
Instead, user code should open/read/write the file directly and handle the
error raised if the file is not available.
To check if a file exists without manipulating it afterwards, access is recommended.
For example, given the following directory structure:
- txtDir
-- file.txt
- app.js
The next program will check for the stats of the given paths:
Asynchronous
stat(2)
. The callback gets two arguments(err, stats)
wherestats
is anfs.Stats
object.In case of an error, the
err.code
will be one ofCommon System Errors
.Using
fs.stat()
to check for the existence of a file before callingfs.open()
,fs.readFile()
orfs.writeFile()
is not recommended. Instead, user code should open/read/write the file directly and handle the error raised if the file is not available.To check if a file exists without manipulating it afterwards, access is recommended.
For example, given the following directory structure:
The next program will check for the stats of the given paths:
The resulting output will resemble:
Since
v0.0.2