get system total disk space in javascript

To get the total disk space of a system in Node.js, you can use the systeminformation package. First, you need to install it by running the following command in your terminal:

npm install systeminformation
30 chars
2 lines

Then, you can use the fsSize() method to get the total disk space in bytes:

const si = require('systeminformation');

si.fsSize(async function (data) {
  const totalDiskSpace = data[0].size;
  console.log(`Total disk space: ${totalDiskSpace} bytes`);
});
179 chars
7 lines

This code will log the total disk space in bytes. However, you can convert it to other units (e.g. GB) by dividing it by the appropriate factor. For example, to get the total disk space in GB, you can use:

const totalDiskSpaceGB = totalDiskSpace / Math.pow(1024, 3);
console.log(`Total disk space: ${totalDiskSpaceGB.toFixed(2)} GB`);
129 chars
3 lines

This will log the total disk space in GB with two decimal places.

gistlibby LogSnag