@@ -3443,6 +3443,7 @@ added: v10.0.0
34433443Closes the file descriptor.
34443444
34453445```js
3446+ const fsPromises = require('fs').promises;
34463447async function openAndClose() {
34473448 let filehandle;
34483449 try {
@@ -3554,6 +3555,9 @@ For example, the following program retains only the first four bytes of the
35543555file:
35553556
35563557```js
3558+ const fs = require('fs');
3559+ const fsPromises = fs.promises;
3560+
35573561console.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
35703574extended part is filled with null bytes (`'\0'`). For example,
35713575
35723576```js
3577+ const fs = require('fs');
3578+ const fsPromises = fs.promises;
3579+
35733580console.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+
36773687fsPromises.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.
37663776Example:
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.
37723782fsPromises.copyFile('source.txt', 'destination.txt')
@@ -3779,6 +3789,7 @@ following example.
37793789
37803790```js
37813791const fs = require('fs');
3792+ const fsPromises = fs.promises;
37823793const { COPYFILE_EXCL } = fs.constants;
37833794
37843795// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
0 commit comments