-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem.js
48 lines (42 loc) · 1.16 KB
/
filesystem.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
43
44
45
46
47
48
const fs = require('fs')
/**
* 1. creating a file
* 2. writing to a file
* 3. reading a file
* 4. view the stats of a file
*/
const createFileAsync = () => {
fs.appendFile('sample.txt', "\nhello world\n", (err) => {
if (err) {
console.error('Error in creating a file and appending to a file :: ', error)
return;
}
console.log('File operation successful')
})
}
const createFile = () => {
fs.appendFileSync('syncsample.txt', "\nhello world\n")
console.log('File operation successful')
}
const readFile = () => {
// const readBuffer = fs.readFileSync("sample.txt")
fs.readFile("sample.txt", (err, data) =>{
if(err) {
console.error('Error in reading the file :: ', err)
return;
}
console.log('Read successful :: ', data.toString())
})
// console.log(readBuffer.toString())
}
const statFile = () => {
fs.stat("sample.txt", (err, stats) => {
if(err) {
console.error('Error in fetching stat of the file :: ', err)
return;
}
console.log('Read stat successful :: ', stats)
})
}
// createFile()
statFile()