File tree Expand file tree Collapse file tree 4 files changed +16
-19
lines changed Expand file tree Collapse file tree 4 files changed +16
-19
lines changed Original file line number Diff line number Diff line change @@ -2,24 +2,19 @@ import fs from "node:fs"
2
2
const x = 1 ;
3
3
const y = 2 ;
4
4
const z = x + y ;
5
- fs . readFile ( "a.txt" ,
6
- //readFile a
7
- ( ) =>
8
- {
5
+ function timer1Callback ( ) { console . log ( "timeout elapsed 1ms" ) }
6
+ function timer2Callback ( ) { fs . readFile ( "c.txt" , readFileCCallback ) }
7
+ function readFileCCallback ( ) { console . log ( "read c after a second" ) }
8
+ function writeFileBCallback ( ) {
9
+ //setTimeout 1000ms
10
+ console . log ( "write b.txt" ) ;
11
+ setTimeout ( timer2Callback , 1000 ) ;
12
+ }
13
+ function readFileACallback ( ) {
9
14
//writeFile b
10
15
console . log ( "read a.txt" ) ;
11
- fs . writeFile ( "b.txt" , "test" , ( ) => {
12
- //setTimeout 1000ms
13
- console . log ( "write b.txt" ) ;
14
- setTimeout ( ( ) => {
15
- fs . readFile ( "c.txt" ,
16
- //read file c
17
- ( ) => console . log ( "read c after a second" )
18
- ) ;
19
- } , 1000 ) ;
20
- } ) ;
21
- } ) ;
22
-
23
-
16
+ fs . writeFile ( "b.txt" , "test" , writeFileBCallback ) ;
17
+ }
18
+ fs . readFile ( "a.txt" , readFileACallback ) ;
24
19
//setTimeout 1ms
25
- setTimeout ( ( ) => console . log ( "timeout elapsed 1ms" ) , 1 ) ;
20
+ setTimeout ( timer1Callback , 1 ) ;
Original file line number Diff line number Diff line change 1
- require ( "/Users/HusseinNasser/projects/node-course-content/01-main-module/010-b.js" )
1
+ //. means from the point of the current __filename
2
+ require ( "./b.js" )
2
3
console . log ( "loading module a" )
3
4
4
5
for ( let i = 0 ; i < 100000000 ; i ++ ) ;
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ test
You can’t perform that action at this time.
0 commit comments