-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-fsPromise.js
More file actions
37 lines (31 loc) · 1.12 KB
/
12-fsPromise.js
File metadata and controls
37 lines (31 loc) · 1.12 KB
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
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');
const second =await readFile('./content/subfolder/test.txt','utf8');
await writeFile('./content/subfolder/promise.txt',`This is edited and creatded using file promise method please revise :(
\\\t ${first} ${second}`,{flag:'a'});
console.log(first, second);
} catch (error) {
console.log(error);
}
}
start()
// const getText = (path) =>{
// return new Promise ((resolve,reject)=>{
// readFile(path,'utf8',(err,data)=>{
// if (err){
// reject(err)
// }else{
// resolve(data)
// console.log(data)
// }
// })
// })
// }
// getText('./content/first.txt')
// .then( result =>console.log(result))
// .catch(err =>console.log(err));