aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorChristopn Noelke <c.noelke@meteocontrol.de>2016-09-17 11:03:04 +0200
committerJames M Snell <jasnell@gmail.com>2016-10-07 09:50:13 -0700
commit23b9625c84e702f17b010bb653df132154ab6cad (patch)
tree28f486021cb523f414ffd8587bde05ac96ac314f /doc
parent105e628f84ad03cfd32ffac112746285be28c872 (diff)
downloadandroid-node-v8-23b9625c84e702f17b010bb653df132154ab6cad.tar.gz
android-node-v8-23b9625c84e702f17b010bb653df132154ab6cad.tar.bz2
android-node-v8-23b9625c84e702f17b010bb653df132154ab6cad.zip
doc: add example for file existence with fs.stat
Add an example on how to test if a file exists with fs.stat. Also add a link to the Common System Errors. Fixes: https://github.com/nodejs/issues/6752 PR-URL: https://github.com/nodejs/node/pull/8585 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/fs.md11
1 files changed, 11 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md
index fef4516958..5cb4b9f422 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -1524,6 +1524,16 @@ Asynchronous stat(2). The callback gets two arguments `(err, stats)` where
`stats` is a [`fs.Stats`][] object. See the [`fs.Stats`][] section for more
information.
+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 calling
+`fs.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, [`fs.access()`]
+is recommended.
+
## fs.statSync(path)
<!-- YAML
added: v0.1.21
@@ -2207,3 +2217,4 @@ The following constants are meant for use with the [`fs.Stats`][] object's
[`event ports`]: http://illumos.org/man/port_create
[`ReadDirectoryChangesW`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v=vs.85%29.aspx
[`AHAFS`]: https://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/
+[Common System Errors]: errors.html#errors_common_system_errors \ No newline at end of file