-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs_demo.js
36 lines (30 loc) · 982 Bytes
/
fs_demo.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
const fs = require('fs');
const path = require('path');
//create a folder
// fs.mkdir(path.join(__dirname, '/test'), {}, err => {
// if (err) throw err;
// console.log('folder created...');
// });
// create and write to file
// fs.writeFile(path.join(__dirname, '/test', 'hello.txt.'), 'hello world', err => {
// if (err) throw err;
// console.log('file writeen to...');
// //append to written file
// fs.appendFile(path.join(__dirname, '/test', 'hello.txt.'), ' I love terraria', err => {
// if (err) throw err;
// console.log('file writeen to...');
// });
// });
//read file
// fs.readFile(path.join(__dirname, '/test', 'hello.txt'), 'utf8', (err, data) => {
// if (err) throw err;
// console.log(data);
// });
//rename file
fs.rename(
path.join(__dirname, '/test', 'hello.txt'),
path.join(__dirname, '/test', 'helloworld.txt'),
err => {
if (err) throw err;
console.log('File renamed...');
});