@@ -3453,6 +3453,7 @@ added: v10.0.0
34533453Closes the file descriptor.
34543454
34553455``` js
3456+ const fsPromises = require (' fs' ).promises ;
34563457async function openAndClose () {
34573458 let filehandle;
34583459 try {
@@ -3564,6 +3565,9 @@ For example, the following program retains only the first four bytes of the
35643565file:
35653566
35663567``` js
3568+ const fs = require (' fs' );
3569+ const fsPromises = fs .promises ;
3570+
35673571console .log (fs .readFileSync (' temp.txt' , ' utf8' ));
35683572// Prints: Node.js
35693573
@@ -3580,6 +3584,9 @@ If the file previously was shorter than `len` bytes, it is extended, and the
35803584extended part is filled with null bytes (` '\0' ` ). For example,
35813585
35823586``` js
3587+ const fs = require (' fs' );
3588+ const fsPromises = fs .promises ;
3589+
35833590console .log (fs .readFileSync (' temp.txt' , ' utf8' ));
35843591// Prints: Node.js
35853592
@@ -3684,6 +3691,9 @@ with an `Error` object. The following example checks if the file
36843691` /etc/passwd ` can be read and written by the current process.
36853692
36863693``` js
3694+ const fs = require (' fs' );
3695+ const fsPromises = fs .promises ;
3696+
36873697fsPromises .access (' /etc/passwd' , fs .constants .R_OK | fs .constants .W_OK )
36883698 .then (() => console .log (' can access' ))
36893699 .catch (() => console .error (' cannot access' ));
@@ -3776,7 +3786,7 @@ then the operation will fail.
37763786Example:
37773787
37783788``` js
3779- const fs = require (' fs' );
3789+ const fsPromises = require (' fs' ). promises ;
37803790
37813791// destination.txt will be created or overwritten by default.
37823792fsPromises .copyFile (' source.txt' , ' destination.txt' )
@@ -3789,6 +3799,7 @@ following example.
37893799
37903800``` js
37913801const fs = require (' fs' );
3802+ const fsPromises = fs .promises ;
37923803const { COPYFILE_EXCL } = fs .constants ;
37933804
37943805// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
0 commit comments