-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Tierney Cyren <[email protected]>
Signed-off-by: Tierney Cyren <[email protected]>
Signed-off-by: Tierney Cyren <[email protected]>
Signed-off-by: Tierney Cyren <[email protected]>
await access('/etc/passwd', constants.R_OK | constants.W_OK); | ||
console.log('can access'); |
There was a problem hiding this comment.
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 <[email protected]>
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!')); |
There was a problem hiding this comment.
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
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!'); |
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 bothfsPromises
andfs
, 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 normalfs
andfsPromises
versions of this method.