-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_FileSystem.js
35 lines (24 loc) · 991 Bytes
/
02_FileSystem.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
// File system
const fs = require('fs');
// Creating a file
function createFile(name, content) {
// name-> name of the file in the same dir or specify the path
// content -> content of new file
// Async
// fs.writeFile(name, content) ;
// Sync
fs.writeFileSync(name, content) ;
// Synchronous and Asynchronous system :
// Sync -> creates the file immidiately, however it's a slow process
// since the node waits for the action to be completed before proceeding
// any further
// Async -> Queues the file creation task and does the job when convinient
// to save time and resource.
console.log('File : '+ name + " created");
}
// Overwritten Dummy.txt if already available
createFile('Dummy.txt', 'Dummy file created using the JS file system.');
console.log(fs.readdirSync('.'));
// console.log(fs) ;
// console all the object properties
console.log(fs.readFileSync('./CommonModuleSystem/02_FileSystem.js', 'utf8'));