Skip to content

Commit 4eedb8d

Browse files
committed
fix modules
1 parent 0bcbabd commit 4eedb8d

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

00-eventloop/001-event-loop-multiple-example.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ import fs from "node:fs"
22
const x = 1;
33
const y = 2;
44
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() {
914
//writeFile b
1015
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);
2419
//setTimeout 1ms
25-
setTimeout( () => console.log("timeout elapsed 1ms"), 1);
20+
setTimeout(timer1Callback, 1);

01-main-module/010-a.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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")
23
console.log("loading module a")
34

45
for (let i = 0; i < 100000000; i ++);
File renamed without changes.

b.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)