@@ -689,9 +689,11 @@ added: v10.0.0
689689
690690Tests a user's permissions for the file or directory specified by ` path` .
691691The ` 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` .
695697
696698If the accessibility check is successful, the promise is resolved with no
697699value. If any of the accessibility checks fail, the promise is rejected
@@ -1561,9 +1563,11 @@ changes:
15611563
15621564Tests a user's permissions for the file or directory specified by `path`.
15631565The `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`.
15671571
15681572The final argument, `callback`, is a callback function that is invoked with
15691573a possible error argument. If any of the accessibility checks fail, the error
@@ -1590,14 +1594,9 @@ access(file, constants.W_OK, (err) => {
15901594 console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
15911595});
15921596
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`);
16011600});
16021601```
16031602
@@ -4389,10 +4388,11 @@ changes:
43894388
43904389Synchronously tests a user's permissions for the file or directory specified
43914390by ` 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` .
43964396
43974397If any of the accessibility checks fail, an ` Error ` will be thrown. Otherwise,
43984398the method will return ` undefined ` .
@@ -6502,7 +6502,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
65026502
65036503##### File access constants
65046504
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 ()` ][].
65066507
65076508<table>
65086509 <tr>
@@ -7181,6 +7182,7 @@ the file contents.
71817182[` event ports` ]: https://illumos.org/man/port_create
71827183[` filehandle .writeFile ()` ]: #filehandlewritefiledata-options
71837184[` fs .access ()` ]: #fsaccesspath-mode-callback
7185+ [` fs .accessSync ()` ]: #fsaccesssyncpath-mode
71847186[` fs .chmod ()` ]: #fschmodpath-mode-callback
71857187[` fs .chown ()` ]: #fschownpath-uid-gid-callback
71867188[` fs .copyFile ()` ]: #fscopyfilesrc-dest-mode-callback
@@ -7215,6 +7217,7 @@ the file contents.
72157217[` fs .write (fd, string... )` ]: #fswritefd-string-position-encoding-callback
72167218[` fs .writeFile ()` ]: #fswritefilefile-data-options-callback
72177219[` fs .writev ()` ]: #fswritevfd-buffers-position-callback
7220+ [` fsPromises .access ()` ]: #fspromisesaccesspath-mode
72187221[` fsPromises .open ()` ]: #fspromisesopenpath-flags-mode
72197222[` fsPromises .opendir ()` ]: #fspromisesopendirpath-options
72207223[` fsPromises .rm ()` ]: #fspromisesrmpath-options
0 commit comments