-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
34 lines (28 loc) · 889 Bytes
/
index.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
// const nodeDiskInfo = require('node-disk-info'); => Use this when install as a dependency
const nodeDiskInfo = require('../dist/index');
// async way
nodeDiskInfo.getDiskInfo()
.then(disks => {
printResults('ASYNC WAY', disks);
})
.catch(reason => {
console.error(reason);
});
// sync way
try {
const disks = nodeDiskInfo.getDiskInfoSync();
printResults('SYNC WAY', disks);
} catch (e) {
console.error(e);
}
function printResults(title, disks) {
console.log(`============ ${title} ==============\n`);
for (const disk of disks) {
console.log('Filesystem:', disk.filesystem);
console.log('Blocks:', disk.blocks);
console.log('Used:', disk.used);
console.log('Available:', disk.available);
console.log('Capacity:', disk.capacity);
console.log('Mounted:', disk.mounted, '\n');
}
}