@@ -738,9 +738,11 @@ added: v10.0.0
738738
739739Tests a user's permissions for the file or directory specified by ` path` .
740740The ` 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` .
744746
745747If the accessibility check is successful, the promise is resolved with no
746748value. If any of the accessibility checks fail, the promise is rejected
@@ -1616,9 +1618,11 @@ changes:
16161618
16171619Tests a user's permissions for the file or directory specified by `path`.
16181620The `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`.
16221626
16231627The final argument, `callback`, is a callback function that is invoked with
16241628a possible error argument. If any of the accessibility checks fail, the error
@@ -1645,14 +1649,9 @@ access(file, constants.W_OK, (err) => {
16451649 console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
16461650});
16471651
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`);
16561655});
16571656```
16581657
@@ -4459,10 +4458,11 @@ changes:
44594458
44604459Synchronously tests a user's permissions for the file or directory specified
44614460by ` 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` .
44664466
44674467If any of the accessibility checks fail, an ` Error ` will be thrown. Otherwise,
44684468the method will return ` undefined ` .
@@ -6579,7 +6579,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
65796579
65806580##### File access constants
65816581
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 ()` ][].
65836584
65846585<table>
65856586 <tr>
@@ -7258,6 +7259,7 @@ the file contents.
72587259[` event ports` ]: https://illumos.org/man/port_create
72597260[` filehandle .writeFile ()` ]: #filehandlewritefiledata-options
72607261[` fs .access ()` ]: #fsaccesspath-mode-callback
7262+ [` fs .accessSync ()` ]: #fsaccesssyncpath-mode
72617263[` fs .chmod ()` ]: #fschmodpath-mode-callback
72627264[` fs .chown ()` ]: #fschownpath-uid-gid-callback
72637265[` fs .copyFile ()` ]: #fscopyfilesrc-dest-mode-callback
@@ -7292,6 +7294,7 @@ the file contents.
72927294[` fs .write (fd, string... )` ]: #fswritefd-string-position-encoding-callback
72937295[` fs .writeFile ()` ]: #fswritefilefile-data-options-callback
72947296[` fs .writev ()` ]: #fswritevfd-buffers-position-callback
7297+ [` fsPromises .access ()` ]: #fspromisesaccesspath-mode
72957298[` fsPromises .open ()` ]: #fspromisesopenpath-flags-mode
72967299[` fsPromises .opendir ()` ]: #fspromisesopendirpath-options
72977300[` fsPromises .rm ()` ]: #fspromisesrmpath-options
0 commit comments