-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-fs-async.js
29 lines (29 loc) · 882 Bytes
/
11-fs-async.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { readFile, writeFile } = require('fs');
console.log('start');
readFile('./content/first.txt', 'utf8', (err, result) => {
if (err) {
console.log(err);
return;
}
const first = result;
readFile('./content/second.txt', 'utf8', (err, result) => {
if (err) {
console.log(err);
return;
}
const second = result;
writeFile(
'./content/result-async.txt',
`Here is the result: ${first}, ${second}`,
{ flag: 'a' }, (err, result) => {
if(err) {
console.log(err);
return;
}
console.log(result);
console.log('done with this task');
})
})
})
console.log('starting next task');
// will return undefined but check the actual async file to see output