File tree 2 files changed +8
-12
lines changed
2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const fs = require ( 'node:fs' ) ;
3
+ const { readFile } = require ( 'node:fs/promises ' ) ;
4
4
5
- const readTextFile = ( filename ) => (
6
- fs . promises . readFile ( filename , 'utf8' )
7
- ) ;
8
-
9
- readTextFile ( 'file1.txt' )
5
+ readFile ( 'file1.txt' , 'utf8' )
10
6
. then ( ( data ) => {
11
7
console . dir ( { file1 : data } ) ;
12
- return readTextFile ( 'file2.txt' ) ;
8
+ return readFile ( 'file2.txt' , 'utf8 ') ;
13
9
} , ( reason ) => {
14
- console . log ( 'Cannot read file1.txt --- A ' ) ;
10
+ console . log ( '1: Cannot read file1.txt' ) ;
15
11
console . log ( reason ) ;
16
12
} )
17
13
. catch ( ( reason ) => {
18
- console . log ( 'Cannot read file1.txt --- B ' ) ;
14
+ console . log ( '2: Cannot read file1.txt' ) ;
19
15
console . log ( reason ) ;
20
16
} )
21
17
. then ( ( data ) => {
22
18
console . dir ( { file2 : data } ) ;
23
- return readTextFile ( 'file3.txt' ) ;
19
+ return readFile ( 'file3.txt' , 'utf8 ') ;
24
20
} )
25
21
. catch ( ( reason ) => {
26
22
console . log ( 'Cannot read file2.txt' ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const fs = require ( 'node:fs' ) ;
3
+ const { readFile } = require ( 'node:fs/promises ' ) ;
4
4
5
- fs . promises . readFile ( 'file1.txt' , 'utf8' )
5
+ readFile ( 'file1.txt' , 'utf8' )
6
6
. then ( ( data ) => {
7
7
console . dir ( { file1 : data } ) ;
8
8
} )
You can’t perform that action at this time.
0 commit comments