How To Get Free Disk Space using NodeJS?

6,945 views
Skip to first unread message

PyroStrex

unread,
Jan 9, 2011, 11:09:53 PM1/9/11
to nodejs
As the title says.. How to get it? Thank you if you helped me :) Like
always, I've searched + check the documentation. Perhaps I missed
something?

cwolves

unread,
Jan 9, 2011, 11:20:05 PM1/9/11
to nodejs
Good question... I'm not sure that Node has this built in... Unless
someone else has an answer, you could always parse this:

require('child_process').exec('df -h', function(err, resp)
{ console.log(resp); });

-Mark

Marak Squires

unread,
Jan 10, 2011, 1:52:50 AM1/10/11
to nod...@googlegroups.com
You could write fixed sized files to disk until you ran out of space and got an error. Then just figure out how many files you wrote and divide. Delete the files when you are done.


...lol 

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.


Michael W

unread,
Jan 11, 2011, 1:05:31 AM1/11/11
to nodejs
I would suggest that the original poster deletes nodejs from his/her
hard drive. That should save a megabyte or two of space.
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .

ck

unread,
Jan 11, 2011, 1:55:00 AM1/11/11
to nodejs
Well, I am not going to work it out for you, as you should figure it
out for yourself (you are the one working on it). If you have to make
your solution robust though, (and maybe you should) you can look at
the source of coreutils/src/df (df is part of the GNU coreutils). Then
you can either make a new _C addon_ to nodejs. You can implement df-
like logic/functionality as much as nodejs allows you to as well. What
cwolves has pointed out is one way of doing it. But you are the master
of your own ship, so you have to know what are your requirements.

I guess a question which needs to be answered is how a tool like df
actually works. In this train of thought, maybe fs.*stat and friends
can be helpful ;-).

btw, if you feel like reading some _c_ code: http://ftp.gnu.org/gnu/coreutils/

Good luck.

PyroStrex

unread,
Jan 12, 2011, 10:53:23 AM1/12/11
to nodejs
Thanks cwolves coz you perfectly answer my question :), to others,
maybe my question was wrong, what i mean was, how to check free disk
space not freeing some disk space :).

ck, ok, your right but to create my own "robust" solution is not quite
right for me who wanna make application fast. :) Thanks anyway. btw,
the link you provided, can't understand it :)

Brice Vandeputte

unread,
Oct 14, 2014, 5:59:29 AM10/14/14
to nod...@googlegroups.com
Since 2011, there is some solution available from repositories

Stephen Vickers

unread,
Oct 17, 2014, 5:28:05 AM10/17/14
to nod...@googlegroups.com
Maybe the storage-device-info module would help you:

Reply all
Reply to author
Forward
0 new messages