@@ -1117,7 +1117,7 @@ try {
1117
1117
1118
1118
` ` ` cjs
1119
1119
const { mkdir } = require (' node:fs/promises' );
1120
- const { resolve , join } = require (' node:path' );
1120
+ const { join } = require (' node:path' );
1121
1121
1122
1122
async function makeDirectory () {
1123
1123
const projectFolder = join (__dirname , ' test' , ' project' );
@@ -1159,9 +1159,11 @@ object with an `encoding` property specifying the character encoding to use.
1159
1159
1160
1160
` ` ` mjs
1161
1161
import { mkdtemp } from ' node:fs/promises' ;
1162
+ import { join } from ' node:path' ;
1163
+ import { tmpdir } from ' node:os' ;
1162
1164
1163
1165
try {
1164
- await mkdtemp (path . join (os . tmpdir (), ' foo-' ));
1166
+ await mkdtemp (join (tmpdir (), ' foo-' ));
1165
1167
} catch (err) {
1166
1168
console .error (err);
1167
1169
}
@@ -3237,8 +3239,10 @@ object with an `encoding` property specifying the character encoding to use.
3237
3239
3238
3240
```mjs
3239
3241
import { mkdtemp } from 'node:fs';
3242
+ import { join } from 'node:path';
3243
+ import { tmpdir } from 'node:os';
3240
3244
3241
- mkdtemp(path. join(os. tmpdir(), 'foo-'), (err, directory) => {
3245
+ mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
3242
3246
if (err) throw err;
3243
3247
console.log(directory);
3244
3248
// 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()`
7542
7546
operation might complete before the `fs.rename()` operation:
7543
7547
7544
7548
```js
7549
+ const fs = require(' node: fs' );
7550
+
7545
7551
fs.rename(' / tmp/ hello' , ' / tmp/ world' , (err) => {
7546
7552
if (err) throw err;
7547
7553
console.log(' renamed complete' );
@@ -7558,12 +7564,12 @@ of one before invoking the other:
7558
7564
```mjs
7559
7565
import { rename, stat } from ' node: fs/ promises' ;
7560
7566
7561
- const from = ' / tmp/ hello' ;
7562
- const to = ' / tmp/ world' ;
7567
+ const oldPath = ' / tmp/ hello' ;
7568
+ const newPath = ' / tmp/ world' ;
7563
7569
7564
7570
try {
7565
- await rename(from, to );
7566
- const stats = await stat(to );
7571
+ await rename(oldPath, newPath );
7572
+ const stats = await stat(newPath );
7567
7573
console.log(`stats: ${JSON.stringify(stats)}`);
7568
7574
} catch (error) {
7569
7575
console.error(' there was an error: ' , error.message);
@@ -7573,10 +7579,10 @@ try {
7573
7579
```cjs
7574
7580
const { rename, stat } = require(' node: fs/ promises' );
7575
7581
7576
- (async function(from, to ) {
7582
+ (async function(oldPath, newPath ) {
7577
7583
try {
7578
- await rename(from, to );
7579
- const stats = await stat(to );
7584
+ await rename(oldPath, newPath );
7585
+ const stats = await stat(newPath );
7580
7586
console.log(`stats: ${JSON.stringify(stats)}`);
7581
7587
} catch (error) {
7582
7588
console.error(' there was an error: ' , error.message);
@@ -7632,7 +7638,7 @@ try {
7632
7638
fd = await open(' / open/ some/ file .txt ' , ' r' );
7633
7639
// Do something with the file
7634
7640
} finally {
7635
- await fd.close();
7641
+ await fd? .close();
7636
7642
}
7637
7643
```
7638
7644
@@ -7646,7 +7652,7 @@ try {
7646
7652
fd = await open(' file .txt ' , ' r' );
7647
7653
// Do something with the file
7648
7654
} finally {
7649
- await fd.close();
7655
+ await fd? .close();
7650
7656
}
7651
7657
```
7652
7658
@@ -7761,7 +7767,7 @@ try {
7761
7767
fd = await open (Buffer .from (' /open/some/file.txt' ), ' r' );
7762
7768
// Do something with the file
7763
7769
} finally {
7764
- await fd .close ();
7770
+ await fd? .close ();
7765
7771
}
7766
7772
` ` `
7767
7773
0 commit comments