-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.js
More file actions
38 lines (31 loc) · 783 Bytes
/
file.js
File metadata and controls
38 lines (31 loc) · 783 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
30
31
32
33
34
35
36
37
38
// Reading content of a file
const fs = require('fs')
// fs.readFile('./blog.txt', (err, data) => {
// if(err){
// console.log(err);
// }
// console.log(data.toString());
// })
// Writing to a file
// fs.writeFile('./blog.txt', 'hello world', () => {
// console.log('file was written');
// })
// to creata a folder
// fs.mkdir('./assets', (err) => {
// if(err){
// console.log(err)
// }
// console.log('folder created');
// })
// fs.writeFile('./assets/newfile', 'this is the new file i created', () => {
// console.log('im done')
// })
// delete files
if (fs.existsSync('./blog.txt')){
fs.unlink('./blog.txt', (err) => {
if (err){
console.log(err)
}
console.log('file deleted');
})
}