@@ -1117,7 +1117,7 @@ try {
11171117
11181118` ` ` cjs
11191119const { mkdir } = require (' node:fs/promises' );
1120- const { resolve , join } = require (' node:path' );
1120+ const { join } = require (' node:path' );
11211121
11221122async function makeDirectory () {
11231123 const projectFolder = join (__dirname , ' test' , ' project' );
@@ -1159,9 +1159,11 @@ object with an `encoding` property specifying the character encoding to use.
11591159
11601160` ` ` mjs
11611161import { mkdtemp } from ' node:fs/promises' ;
1162+ import { join } from ' node:path' ;
1163+ import { tmpdir } from ' node:os' ;
11621164
11631165try {
1164- await mkdtemp (path . join (os . tmpdir (), ' foo-' ));
1166+ await mkdtemp (join (tmpdir (), ' foo-' ));
11651167} catch (err) {
11661168 console .error (err);
11671169}
@@ -3237,8 +3239,10 @@ object with an `encoding` property specifying the character encoding to use.
32373239
32383240```mjs
32393241import { mkdtemp } from 'node:fs';
3242+ import { join } from 'node:path';
3243+ import { tmpdir } from 'node:os';
32403244
3241- mkdtemp(path. join(os. tmpdir(), 'foo-'), (err, directory) => {
3245+ mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
32423246 if (err) throw err;
32433247 console.log(directory);
32443248 // Prints: /tmp/foo-itXde2 or C:\U sers\. ..\A ppData\L ocal\T emp\f oo-itXde2
@@ -7542,6 +7546,8 @@ For example, the following is prone to error because the `fs.stat()`
75427546operation might complete before the `fs.rename()` operation:
75437547
75447548```js
7549+ const fs = require(' node: fs' );
7550+
75457551fs.rename(' / tmp/ hello' , ' / tmp/ world' , (err) => {
75467552 if (err) throw err;
75477553 console.log(' renamed complete' );
@@ -7558,12 +7564,12 @@ of one before invoking the other:
75587564```mjs
75597565import { rename, stat } from ' node: fs/ promises' ;
75607566
7561- const from = ' / tmp/ hello' ;
7562- const to = ' / tmp/ world' ;
7567+ const oldPath = ' / tmp/ hello' ;
7568+ const newPath = ' / tmp/ world' ;
75637569
75647570try {
7565- await rename(from, to );
7566- const stats = await stat(to );
7571+ await rename(oldPath, newPath );
7572+ const stats = await stat(newPath );
75677573 console.log(`stats: ${JSON.stringify(stats)}`);
75687574} catch (error) {
75697575 console.error(' there was an error: ' , error.message);
@@ -7573,10 +7579,10 @@ try {
75737579```cjs
75747580const { rename, stat } = require(' node: fs/ promises' );
75757581
7576- (async function(from, to ) {
7582+ (async function(oldPath, newPath ) {
75777583 try {
7578- await rename(from, to );
7579- const stats = await stat(to );
7584+ await rename(oldPath, newPath );
7585+ const stats = await stat(newPath );
75807586 console.log(`stats: ${JSON.stringify(stats)}`);
75817587 } catch (error) {
75827588 console.error(' there was an error: ' , error.message);
@@ -7632,7 +7638,7 @@ try {
76327638 fd = await open(' / open/ some/ file .txt ' , ' r' );
76337639 // Do something with the file
76347640} finally {
7635- await fd.close();
7641+ await fd? .close();
76367642}
76377643```
76387644
@@ -7646,7 +7652,7 @@ try {
76467652 fd = await open(' file .txt ' , ' r' );
76477653 // Do something with the file
76487654} finally {
7649- await fd.close();
7655+ await fd? .close();
76507656}
76517657```
76527658
@@ -7761,7 +7767,7 @@ try {
77617767 fd = await open (Buffer .from (' /open/some/file.txt' ), ' r' );
77627768 // Do something with the file
77637769} finally {
7764- await fd .close ();
7770+ await fd? .close ();
77657771}
77667772` ` `
77677773
0 commit comments