-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (65 loc) · 2.23 KB
/
server.js
File metadata and controls
73 lines (65 loc) · 2.23 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// console.log("Server is starting...");
//console.log(global);
// const os=require('os');
// console.log("OS Type: " + os.type());
// console.log("OS Platform: " + os.platform());
// console.log("OS Release: " + os.release());
// console.log("OS Architecture: " + os.homedir());
// console.log(__dirname)
// console.log(__filename)
// const path = require('path');
// console.log("Path Separator: " + path.dirname(__filename));
// console.log("Path Separator: " + path.basename(__filename));
// console.log("Path Separator: " + path.extname(__filename));
// console.log(path.parse(__filename));
// const add1 = require('./math').add;
// const subtract2 = require('./math').subtract;
// const multiply = require('./math').multiply;
// const divide = require('./math').divide;
// const { add, subtract,multiply,divide } = require('./math');
// console.log("Addition: " + add(5, 3));
// console.log("Subtraction: " + subtract(5, 3));
const fs=require('fs');
const path=require('path');
const filePath = path.join(__dirname, 'Files', 'rename.txt');
// console.log(filePath)
const fspromise=require('fs').promises
const fileops=async () => {
try {
const data = await fspromise.readFile(filePath, 'utf8')
await fspromise.writeFile(filePath, 'jhkjkj!')
await fspromise.unlink(filePath)
console.log('File content:', data);
}catch (err) {
console.error('Error:', err);
}
}
fileops();
// fs.readFile(filePath, 'utf8', (err, data) => {
// if (err) {
// console.error('Error reading file:', err);
// return;
// }
// console.log('File content:', data);
// });
// fs.writeFile(filePath, 'Hello, this is a new content!', (err) => {
// if (err) {
// console.error('Error writing file:', err);
// return;
// }
// console.log('File written successfully!');
// });
// fs.appendFile(filePath, 'Thank you for sub!', (err) => {
// if (err) {
// console.error('Error writing file:', err);
// return;
// }
// console.log('File written successfully!');
// });
// fs.rename(path.join(__dirname, 'Files', 'start.txt'),path.join(__dirname, 'Files', 'rename.txt'), (err) => {
// if (err) {
// console.error('Error writing file:', err);
// return;
// }
// console.log('rename' + 'File written successfully!');
// });