Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add ESM and CommonJS examples in fs documentation #52207

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bnb
Copy link
Contributor

@bnb bnb commented Mar 25, 2024

This PR adds a handful of code examples to fs methods where code examples were either entirely omitted or were only available for ESM. This includes code examples for both fsPromises and fs, trying to keep them in lockstep.

This includes a code example for a method, fs.chown, that was added in Node.js v0.1.97 and seemingly has never had a code example. I've added ESM and CommonJS examples for both the normal fs and fsPromises versions of this method.

bnb added 3 commits March 14, 2024 15:59
Signed-off-by: Tierney Cyren <hello@bnb.im>
Signed-off-by: Tierney Cyren <hello@bnb.im>
Signed-off-by: Tierney Cyren <hello@bnb.im>
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Mar 25, 2024
Signed-off-by: Tierney Cyren <hello@bnb.im>
Comment on lines +906 to +907
await access('/etc/passwd', constants.R_OK | constants.W_OK);
console.log('can access');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right to me, actually. Specifically, I think the console.log() can trigger despite the access failing.

Signed-off-by: Tierney Cyren <hello@bnb.im>
import { chmod } from 'node:fs/promises';

try {
await chmod('my_file.txt', 0o775).then(console.log('The permissions for file "my_file.txt" have been changed!'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's much more readable as two separate expressions

Suggested change
await chmod('my_file.txt', 0o775).then(console.log('The permissions for file "my_file.txt" have been changed!'));
await chmod('my_file.txt', 0o775);
console.log('The permissions for file "my_file.txt" have been changed!');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants