-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOperations.js
More file actions
29 lines (24 loc) · 929 Bytes
/
fileOperations.js
File metadata and controls
29 lines (24 loc) · 929 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 first = fs.readFileSync('./content/sub-folder/first.text', 'utf8');
console.log(first);
const second = fs.writeFileSync('./content/sub-folder/second.text', `Hello World here is the result ${first} `);
// ayncrhous method
const third = fs.readFileSync('./content/sub-folder/second.text', 'utf8');
// synchronous method
// const third = fs.readFile('./content/sub-folder/second.text', 'utf8', (err, result) => {
// if(err){
// console.log(err);
// return;
// }
// console.log(result);
// });
console.log(third);
// fs.mkdir('./content/sub-folder', { recursive: true }, (err) => {
// if(err){
// console.log(err);
// return;
// }
// console.log('Folder created');
// });
// so fs is used to read and write files, create and delete files and folders, watch files and folders for changes, etc.
// fs.readdir('./content', (err, files) =>