-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescribePathAndFs.js
More file actions
28 lines (24 loc) · 954 Bytes
/
Copy pathDescribePathAndFs.js
File metadata and controls
28 lines (24 loc) · 954 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
const path = require('path');
const fs = require('fs');
// Function name: explorePathAndFs
function explorePathAndFs() {
// 1. Path module demonstration
const filePath = '/home/user/project/data.txt';
console.log("--- Path Module ---");
console.log("Basename:", path.basename(filePath));
console.log("Directory:", path.dirname(filePath));
console.log("Extension:", path.extname(filePath));
// 2. FS module demonstration (joining path and reading)
console.log("\n--- FS Module ---");
const absolutePath = path.join(__dirname, 'DescribePathAndFs.js');
console.log("Reading file at:", absolutePath);
fs.readFile(absolutePath, 'utf8', (err, data) => {
if (err) {
console.error("Error reading file:", err);
return;
}
console.log("Successfully read first 50 characters of this file:");
console.log(data.substring(0, 50));
});
}
explorePathAndFs();