@@ -689,9 +689,11 @@ added: v10.0.0
689
689
690
690
Tests a user's permissions for the file or directory specified by ` path` .
691
691
The ` mode` argument is an optional integer that specifies the accessibility
692
- checks to be performed. Check [File access constants][] for possible values
693
- of ` mode` . It is possible to create a mask consisting of the bitwise OR of
694
- two or more values (e.g. ` fs .constants .W_OK | fs .constants .R_OK ` ).
692
+ checks to be performed. ` mode` should be either the value ` fs .constants .F_OK `
693
+ or a mask consisting of the bitwise OR of any of ` fs .constants .R_OK ` ,
694
+ ` fs .constants .W_OK ` , and ` fs .constants .X_OK ` (e.g.
695
+ ` fs .constants .W_OK | fs .constants .R_OK ` ). Check [File access constants][] for
696
+ possible values of ` mode` .
695
697
696
698
If the accessibility check is successful, the promise is resolved with no
697
699
value. If any of the accessibility checks fail, the promise is rejected
@@ -1561,9 +1563,11 @@ changes:
1561
1563
1562
1564
Tests a user's permissions for the file or directory specified by `path`.
1563
1565
The `mode` argument is an optional integer that specifies the accessibility
1564
- checks to be performed. Check [File access constants][] for possible values
1565
- of `mode`. It is possible to create a mask consisting of the bitwise OR of
1566
- two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
1566
+ checks to be performed. `mode` should be either the value `fs.constants.F_OK`
1567
+ or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
1568
+ `fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
1569
+ `fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
1570
+ possible values of `mode`.
1567
1571
1568
1572
The final argument, `callback`, is a callback function that is invoked with
1569
1573
a possible error argument. If any of the accessibility checks fail, the error
@@ -1590,14 +1594,9 @@ access(file, constants.W_OK, (err) => {
1590
1594
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
1591
1595
});
1592
1596
1593
- // Check if the file exists in the current directory, and if it is writable.
1594
- access(file, constants.F_OK | constants.W_OK, (err) => {
1595
- if (err) {
1596
- console.error(
1597
- `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
1598
- } else {
1599
- console.log(`${file} exists, and it is writable`);
1600
- }
1597
+ // Check if the file is readable and writable.
1598
+ access(file, constants.R_OK | constants.W_OK, (err) => {
1599
+ console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
1601
1600
});
1602
1601
```
1603
1602
@@ -4389,10 +4388,11 @@ changes:
4389
4388
4390
4389
Synchronously tests a user's permissions for the file or directory specified
4391
4390
by ` path` . The ` mode` argument is an optional integer that specifies the
4392
- accessibility checks to be performed. Check [File access constants][] for
4393
- possible values of ` mode` . It is possible to create a mask consisting of
4394
- the bitwise OR of two or more values
4395
- (e.g. ` fs .constants .W_OK | fs .constants .R_OK ` ).
4391
+ accessibility checks to be performed. ` mode` should be either the value
4392
+ ` fs .constants .F_OK ` or a mask consisting of the bitwise OR of any of
4393
+ ` fs .constants .R_OK ` , ` fs .constants .W_OK ` , and ` fs .constants .X_OK ` (e.g.
4394
+ ` fs .constants .W_OK | fs .constants .R_OK ` ). Check [File access constants][] for
4395
+ possible values of ` mode` .
4396
4396
4397
4397
If any of the accessibility checks fail, an ` Error ` will be thrown. Otherwise,
4398
4398
the method will return ` undefined ` .
@@ -6502,7 +6502,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
6502
6502
6503
6503
##### File access constants
6504
6504
6505
- The following constants are meant for use with [` fs .access ()` ][].
6505
+ The following constants are meant for use as the ` mode` parameter passed to
6506
+ [` fsPromises .access ()` ][], [` fs .access ()` ][], and [` fs .accessSync ()` ][].
6506
6507
6507
6508
<table>
6508
6509
<tr>
@@ -7181,6 +7182,7 @@ the file contents.
7181
7182
[` event ports` ]: https://illumos.org/man/port_create
7182
7183
[` filehandle .writeFile ()` ]: #filehandlewritefiledata-options
7183
7184
[` fs .access ()` ]: #fsaccesspath-mode-callback
7185
+ [` fs .accessSync ()` ]: #fsaccesssyncpath-mode
7184
7186
[` fs .chmod ()` ]: #fschmodpath-mode-callback
7185
7187
[` fs .chown ()` ]: #fschownpath-uid-gid-callback
7186
7188
[` fs .copyFile ()` ]: #fscopyfilesrc-dest-mode-callback
@@ -7215,6 +7217,7 @@ the file contents.
7215
7217
[` fs .write (fd, string... )` ]: #fswritefd-string-position-encoding-callback
7216
7218
[` fs .writeFile ()` ]: #fswritefilefile-data-options-callback
7217
7219
[` fs .writev ()` ]: #fswritevfd-buffers-position-callback
7220
+ [` fsPromises .access ()` ]: #fspromisesaccesspath-mode
7218
7221
[` fsPromises .open ()` ]: #fspromisesopenpath-flags-mode
7219
7222
[` fsPromises .opendir ()` ]: #fspromisesopendirpath-options
7220
7223
[` fsPromises .rm ()` ]: #fspromisesrmpath-options
0 commit comments