Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
doc: fix fs.promises sample codes.
  • Loading branch information
kakts committed May 19, 2018
commit ed248867545505598c0e8a5c3e96cbe67159146a
14 changes: 12 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,7 @@ added: v10.0.0
Closes the file descriptor.

```js
const fsPromises = require('fs').promises;
async function openAndClose() {
let filehandle;
try {
Expand Down Expand Up @@ -3564,6 +3565,9 @@ For example, the following program retains only the first four bytes of the
file:

```js
const fs = require('fs');
const fsPromises = fs.promises;

console.log(fs.readFileSync('temp.txt', 'utf8'));
// Prints: Node.js

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

```js
const fs = require('fs');
const fsPromises = fs.promises;

console.log(fs.readFileSync('temp.txt', 'utf8'));
// Prints: Node.js

Expand Down Expand Up @@ -3684,6 +3691,9 @@ with an `Error` object. The following example checks if the file
`/etc/passwd` can be read and written by the current process.

```js
const fs = require('fs');
const fsPromises = fs.promises;

fsPromises.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK)
.then(() => console.log('can access'))
.catch(() => console.error('cannot access'));
Expand Down Expand Up @@ -3776,7 +3786,7 @@ then the operation will fail.
Example:

```js
const fs = require('fs');
const fsPromises = require('fs').promises;

// destination.txt will be created or overwritten by default.
fsPromises.copyFile('source.txt', 'destination.txt')
Expand All @@ -3788,7 +3798,7 @@ If the third argument is a number, then it specifies `flags`, as shown in the
following example.

```js
const fs = require('fs');
const fsPromises = require('fs').promises;
const { COPYFILE_EXCL } = fs.constants;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fs is undefined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. 726be35


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