-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfilesystem.js
More file actions
50 lines (40 loc) · 1.01 KB
/
filesystem.js
File metadata and controls
50 lines (40 loc) · 1.01 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let fs = require('fs');
const filename="example_text_file.txt";
//Creates a new empty file if it does not exist.
/*
fs.open(filename, 'w', function (err, file) {
if (err) throw err;
console.log("File opened", file);
});
//Append content to one existing file
fs.appendFile(
filename,
"File new content appended.",
function (err) {
if (err) throw err;
console.log('Content appended!');
}
);
*/
//Read file content
fs.readFile(
filename,
function(err, data) {
if (err) throw err;
console.log('File content:',data, data.toString() );
}
);
fs.writeFile(filename, 'NEW FILE CONTENT', function (err) {
if (err) throw err;
console.log('Content writen.');
});
/*
fs.unlink(filename, function (err) {
if (err) throw err;
console.log('File deleted!');
});
*/
fs.rename(filename, 'new_file_name_renamed.txt', function (err) {
if (err) throw err;
console.log('File Renamed!');
});