-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurd.js
More file actions
30 lines (22 loc) · 660 Bytes
/
curd.js
File metadata and controls
30 lines (22 loc) · 660 Bytes
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 fs = require('fs');
const path = require('path');
const dirPath = path.join(__dirname , 'curd');
const filePath = `${dirPath}/hello.txt`;
// Creating a file
fs.writeFileSync(filePath , 'this is a simple text');
// reading the file
fs.readFile(filePath , "utf8" , (err , item) => {
console.log(item);
})
// appending a file
fs.appendFile(filePath , ' and this an apple.txt file' , (err) => {
if(!err)
console.log('file is updated');
} );
//renaming the file
fs.rename(filePath , `${dirPath}/fruit.txt` , (err) => {
if(!err)
console.log('file name is updated')
});
// deleting the file
//fs.unlinkSync(`${dirPath}/fruit.txt`);