doc: update examples of the final "callback" argument for fs.access()#20460
doc: update examples of the final "callback" argument for fs.access()#20460BeniCheni wants to merge 5 commits intonodejs:masterfrom BeniCheni:fs-md-updt-dot-access
Conversation
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Nits:
and/or->andcould be written to->is writable
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Nit: could not be written to -> is not writable
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Nit: could not be read -> is readable
There was a problem hiding this comment.
is not readable / is readable?
There was a problem hiding this comment.
@vsemozhetbyt Yes, I forgot the not. Should be:
Nit: could not be read -> is not readable
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Nit: could be written to -> is writable
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Same with the comment: could be written to -> is writable
|
I wonder if the example code can be pared down a bit without losing any information. (I don't know if it can; I'm asking.) @nodejs/documentation @nodejs/fs |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
`package.json` for consistency?
|
🙏 for 1st round of review @Trott & @vsemozhetbyt. I've read your feedback and updated the content to emphasize contextually more on the suggested "readable" & "writable" keywords in the latest updates. Please review again? I also saw the "pared down a bit" comment, which I'll look out for any further suggested feedback to account for that potential update. (happy to update it to if any suggest arises on that topic) |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
It seems this can be unwrapped now like in the block above, to spare some lines)
|
@BeniCheni @Trott Minimal changes I could think of (-11 lines without major refactoring): Code:const file = 'package.json';
// Check if the file exists in the current directory.
fs.access(file, fs.constants.F_OK, (err) => {
console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
});
// Check if the file is readable.
fs.access(file, fs.constants.R_OK, (err) => {
console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
});
// Check if the file is writable.
fs.access(file, fs.constants.W_OK, (err) => {
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
});
// Check if the file exists in the current directory, and if it is writable.
fs.access(file, fs.constants.F_OK | fs.constants.W_OK, (err) => {
if (err) {
console.error(
`${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
} else {
console.log(`${file} exists, and it is writable`);
}
}); |
|
(And it seems |
|
@vsemozhetbyt , nice refactoring suggestion. I worked with the suggested code to update the PR, as well as removed the not so useful |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
We can also replace './package.json' with just file here and in the next calls)
…js examples for fs.access()
|
Sounds good, @vsemozhetbyt. Updated the |
|
@Trott Can we land it in this variant? |
@vsemozhetbyt I have no objections. |
|
(Missed CI-lite link: https://ci.nodejs.org/job/node-test-pull-request-lite/650/) |
|
Landed in b4ca3a4 |
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesFixes: #17508
Per this following comment (as the origin of the aspiration to help out #17508), I've confirmed with the @ gireeshpunathil, and worked with the suggested content of #17578.
Hope that the attempted
fs.accesssnippets look okay in the PR. Happy to update according to review feedback. Thanks for reviewing in advance.