summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe <afvasquezt@gmail.com>2019-06-21 23:29:00 -0500
committerAnna Henningsen <anna@addaleax.net>2019-07-03 22:21:10 +0200
commitc03df4c75d7ca9688865701b553e3843f80fda52 (patch)
tree966fe07f164821f0d15bb77bd6e1790064b673fd
parent8df76e6d47896322aba7a7945d4c7802fc3d5936 (diff)
downloadandroid-node-v8-c03df4c75d7ca9688865701b553e3843f80fda52.tar.gz
android-node-v8-c03df4c75d7ca9688865701b553e3843f80fda52.tar.bz2
android-node-v8-c03df4c75d7ca9688865701b553e3843f80fda52.zip
doc: provide an example to fs.stat()
Provided a small example along its output using fs.stat() to check the stats on two different paths, one a directory and the other a txt file. PR-URL: https://github.com/nodejs/node/pull/28381 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
-rw-r--r--doc/api/fs.md70
1 files changed, 70 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md
index 568e7447f0..a637a22edc 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -3082,6 +3082,76 @@ error raised if the file is not available.
To check if a file exists without manipulating it afterwards, [`fs.access()`]
is recommended.
+For example, given the following folder structure:
+
+```fundamental
+- txtDir
+-- file.txt
+- app.js
+```
+
+The next program will check for the stats of the given paths:
+
+```js
+const fs = require('fs');
+
+const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
+
+for (let i = 0; i < pathsToCheck.length; i++) {
+ fs.stat(pathsToCheck[i], function(err, stats) {
+ console.log(stats.isDirectory());
+ console.log(stats);
+ });
+}
+```
+
+The resulting output will resemble:
+
+```console
+true
+Stats {
+ dev: 16777220,
+ mode: 16877,
+ nlink: 3,
+ uid: 501,
+ gid: 20,
+ rdev: 0,
+ blksize: 4096,
+ ino: 14214262,
+ size: 96,
+ blocks: 0,
+ atimeMs: 1561174653071.963,
+ mtimeMs: 1561174614583.3518,
+ ctimeMs: 1561174626623.5366,
+ birthtimeMs: 1561174126937.2893,
+ atime: 2019-06-22T03:37:33.072Z,
+ mtime: 2019-06-22T03:36:54.583Z,
+ ctime: 2019-06-22T03:37:06.624Z,
+ birthtime: 2019-06-22T03:28:46.937Z
+}
+false
+Stats {
+ dev: 16777220,
+ mode: 33188,
+ nlink: 1,
+ uid: 501,
+ gid: 20,
+ rdev: 0,
+ blksize: 4096,
+ ino: 14214074,
+ size: 8,
+ blocks: 8,
+ atimeMs: 1561174616618.8555,
+ mtimeMs: 1561174614584,
+ ctimeMs: 1561174614583.8145,
+ birthtimeMs: 1561174007710.7478,
+ atime: 2019-06-22T03:36:56.619Z,
+ mtime: 2019-06-22T03:36:54.584Z,
+ ctime: 2019-06-22T03:36:54.584Z,
+ birthtime: 2019-06-22T03:26:47.711Z
+}
+```
+
## fs.statSync(path[, options])
<!-- YAML
added: v0.1.21