File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const fs = require ( 'node:fs' ) ;
3+ const { readFile } = require ( 'node:fs/promises ' ) ;
44
5- const readTextFile = ( filename ) => (
6- fs . promises . readFile ( filename , 'utf8' )
7- ) ;
8-
9- readTextFile ( 'file1.txt' )
5+ readFile ( 'file1.txt' , 'utf8' )
106 . then ( ( data ) => {
117 console . dir ( { file1 : data } ) ;
12- return readTextFile ( 'file2.txt' ) ;
8+ return readFile ( 'file2.txt' , 'utf8 ') ;
139 } , ( reason ) => {
14- console . log ( 'Cannot read file1.txt --- A ' ) ;
10+ console . log ( '1: Cannot read file1.txt' ) ;
1511 console . log ( reason ) ;
1612 } )
1713 . catch ( ( reason ) => {
18- console . log ( 'Cannot read file1.txt --- B ' ) ;
14+ console . log ( '2: Cannot read file1.txt' ) ;
1915 console . log ( reason ) ;
2016 } )
2117 . then ( ( data ) => {
2218 console . dir ( { file2 : data } ) ;
23- return readTextFile ( 'file3.txt' ) ;
19+ return readFile ( 'file3.txt' , 'utf8 ') ;
2420 } )
2521 . catch ( ( reason ) => {
2622 console . log ( 'Cannot read file2.txt' ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const fs = require ( 'node:fs' ) ;
3+ const { readFile } = require ( 'node:fs/promises ' ) ;
44
5- fs . promises . readFile ( 'file1.txt' , 'utf8' )
5+ readFile ( 'file1.txt' , 'utf8' )
66 . then ( ( data ) => {
77 console . dir ( { file1 : data } ) ;
88 } )
You can’t perform that action at this time.
0 commit comments