To get the free disk space of the system using JavaScript and Node.js, we can use the built-in Node.js module os
. Here's an example code snippet that gets the free disk space in bytes:
162 chars7 lines
The os.freemem()
method returns the free memory in bytes as an integer. We can use this method to get the free disk space on the system where our code is running.
If you'd like to convert the result to another unit like kilobytes, megabytes, or gigabytes, you can use simple arithmetic operations. Here's an example code snippet that converts the free disk space to gigabytes:
271 chars10 lines
This will print the free disk space in gigabytes, rounded to two decimal places.
gistlibby LogSnag