@@ -738,9 +738,11 @@ added: v10.0.0
738
738
739
739
Tests a user's permissions for the file or directory specified by ` path` .
740
740
The ` mode` argument is an optional integer that specifies the accessibility
741
- checks to be performed. Check [File access constants][] for possible values
742
- of ` mode` . It is possible to create a mask consisting of the bitwise OR of
743
- two or more values (e.g. ` fs .constants .W_OK | fs .constants .R_OK ` ).
741
+ checks to be performed. ` mode` should be either the value ` fs .constants .F_OK `
742
+ or a mask consisting of the bitwise OR of any of ` fs .constants .R_OK ` ,
743
+ ` fs .constants .W_OK ` , and ` fs .constants .X_OK ` (e.g.
744
+ ` fs .constants .W_OK | fs .constants .R_OK ` ). Check [File access constants][] for
745
+ possible values of ` mode` .
744
746
745
747
If the accessibility check is successful, the promise is resolved with no
746
748
value. If any of the accessibility checks fail, the promise is rejected
@@ -1616,9 +1618,11 @@ changes:
1616
1618
1617
1619
Tests a user's permissions for the file or directory specified by `path`.
1618
1620
The `mode` argument is an optional integer that specifies the accessibility
1619
- checks to be performed. Check [File access constants][] for possible values
1620
- of `mode`. It is possible to create a mask consisting of the bitwise OR of
1621
- two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
1621
+ checks to be performed. `mode` should be either the value `fs.constants.F_OK`
1622
+ or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
1623
+ `fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
1624
+ `fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
1625
+ possible values of `mode`.
1622
1626
1623
1627
The final argument, `callback`, is a callback function that is invoked with
1624
1628
a possible error argument. If any of the accessibility checks fail, the error
@@ -1645,14 +1649,9 @@ access(file, constants.W_OK, (err) => {
1645
1649
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
1646
1650
});
1647
1651
1648
- // Check if the file exists in the current directory, and if it is writable.
1649
- access(file, constants.F_OK | constants.W_OK, (err) => {
1650
- if (err) {
1651
- console.error(
1652
- `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
1653
- } else {
1654
- console.log(`${file} exists, and it is writable`);
1655
- }
1652
+ // Check if the file is readable and writable.
1653
+ access(file, constants.R_OK | constants.W_OK, (err) => {
1654
+ console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
1656
1655
});
1657
1656
```
1658
1657
@@ -4459,10 +4458,11 @@ changes:
4459
4458
4460
4459
Synchronously tests a user's permissions for the file or directory specified
4461
4460
by ` path` . The ` mode` argument is an optional integer that specifies the
4462
- accessibility checks to be performed. Check [File access constants][] for
4463
- possible values of ` mode` . It is possible to create a mask consisting of
4464
- the bitwise OR of two or more values
4465
- (e.g. ` fs .constants .W_OK | fs .constants .R_OK ` ).
4461
+ accessibility checks to be performed. ` mode` should be either the value
4462
+ ` fs .constants .F_OK ` or a mask consisting of the bitwise OR of any of
4463
+ ` fs .constants .R_OK ` , ` fs .constants .W_OK ` , and ` fs .constants .X_OK ` (e.g.
4464
+ ` fs .constants .W_OK | fs .constants .R_OK ` ). Check [File access constants][] for
4465
+ possible values of ` mode` .
4466
4466
4467
4467
If any of the accessibility checks fail, an ` Error ` will be thrown. Otherwise,
4468
4468
the method will return ` undefined ` .
@@ -6579,7 +6579,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
6579
6579
6580
6580
##### File access constants
6581
6581
6582
- The following constants are meant for use with [` fs .access ()` ][].
6582
+ The following constants are meant for use as the ` mode` parameter passed to
6583
+ [` fsPromises .access ()` ][], [` fs .access ()` ][], and [` fs .accessSync ()` ][].
6583
6584
6584
6585
<table>
6585
6586
<tr>
@@ -7258,6 +7259,7 @@ the file contents.
7258
7259
[` event ports` ]: https://illumos.org/man/port_create
7259
7260
[` filehandle .writeFile ()` ]: #filehandlewritefiledata-options
7260
7261
[` fs .access ()` ]: #fsaccesspath-mode-callback
7262
+ [` fs .accessSync ()` ]: #fsaccesssyncpath-mode
7261
7263
[` fs .chmod ()` ]: #fschmodpath-mode-callback
7262
7264
[` fs .chown ()` ]: #fschownpath-uid-gid-callback
7263
7265
[` fs .copyFile ()` ]: #fscopyfilesrc-dest-mode-callback
@@ -7292,6 +7294,7 @@ the file contents.
7292
7294
[` fs .write (fd, string... )` ]: #fswritefd-string-position-encoding-callback
7293
7295
[` fs .writeFile ()` ]: #fswritefilefile-data-options-callback
7294
7296
[` fs .writev ()` ]: #fswritevfd-buffers-position-callback
7297
+ [` fsPromises .access ()` ]: #fspromisesaccesspath-mode
7295
7298
[` fsPromises .open ()` ]: #fspromisesopenpath-flags-mode
7296
7299
[` fsPromises .opendir ()` ]: #fspromisesopendirpath-options
7297
7300
[` fsPromises .rm ()` ]: #fspromisesrmpath-options
0 commit comments