Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8317a46

Browse filesBrowse files
kaktsMylesBorins
authored andcommitted
doc: fix fs.promises sample codes
PR-URL: #20838 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 37b9fe1 commit 8317a46
Copy full SHA for 8317a46

File tree

Expand file treeCollapse file tree

1 file changed

+12
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+12-1Lines changed: 12 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,7 @@ added: v10.0.0
34433443
Closes the file descriptor.
34443444

34453445
```js
3446+
const fsPromises = require('fs').promises;
34463447
async function openAndClose() {
34473448
let filehandle;
34483449
try {
@@ -3554,6 +3555,9 @@ For example, the following program retains only the first four bytes of the
35543555
file:
35553556

35563557
```js
3558+
const fs = require('fs');
3559+
const fsPromises = fs.promises;
3560+
35573561
console.log(fs.readFileSync('temp.txt', 'utf8'));
35583562
// Prints: Node.js
35593563

@@ -3570,6 +3574,9 @@ If the file previously was shorter than `len` bytes, it is extended, and the
35703574
extended part is filled with null bytes (`'\0'`). For example,
35713575

35723576
```js
3577+
const fs = require('fs');
3578+
const fsPromises = fs.promises;
3579+
35733580
console.log(fs.readFileSync('temp.txt', 'utf8'));
35743581
// Prints: Node.js
35753582

@@ -3674,6 +3681,9 @@ with an `Error` object. The following example checks if the file
36743681
`/etc/passwd` can be read and written by the current process.
36753682

36763683
```js
3684+
const fs = require('fs');
3685+
const fsPromises = fs.promises;
3686+
36773687
fsPromises.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK)
36783688
.then(() => console.log('can access'))
36793689
.catch(() => console.error('cannot access'));
@@ -3766,7 +3776,7 @@ then the operation will fail.
37663776
Example:
37673777

37683778
```js
3769-
const fs = require('fs');
3779+
const fsPromises = require('fs').promises;
37703780

37713781
// destination.txt will be created or overwritten by default.
37723782
fsPromises.copyFile('source.txt', 'destination.txt')
@@ -3779,6 +3789,7 @@ following example.
37793789

37803790
```js
37813791
const fs = require('fs');
3792+
const fsPromises = fs.promises;
37823793
const { COPYFILE_EXCL } = fs.constants;
37833794

37843795
// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.