-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14-promises.js
42 lines (32 loc) · 1.05 KB
/
14-promises.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
30
31
32
33
34
35
36
37
38
39
40
41
42
const {readFile, writeFile} = require('fs').promises;
// const util = require('util');
// const readFilePromise = util.promisify(readFile);
// const writeFilePromise = util.promisify(writeFile);
const start = async() => {
try{
const first = await readFile('./content/first.txt', 'utf8');
console.log(first)
const second = await readFile('./content/second.txt', 'utf8');
console.log(second)
await writeFile('./content/result-writeFilePromise.txt', `THIS IS AWESOME: ${first} ${second}`, {flag:'a'})
}
catch (error) {
console.log(error);
}
}
start();
// const getText = (path)=>{
// return new Promise((resolve, reject)=>{
// readFile('./content/first.txt', 'utf8', (err, data)=>{
// if(err){
// reject(err);
// }
// else {
// resolve(data);
// }
// });
// });
// };
// getText('./content/first.txt')
// .then((result) => {console.log(result)})
// .catch((err)=>{console.log(err)});