Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I create a RAM disk using Node.js?

How do I create a RAM disk using Node.js?


I would like to create a Ram Disk programmatically using Node.js, no matter what the underlying OS is (OS X, Linux and Windows should be supported).

What is the best way to achieve this?

Of course I can run a command as a child process, but I would need to write this code individually for each OS. For obvious reasons I'd like to avoid this.

Is there a better approach (even a module that does it would be fine)?

Problem courtesy of: Golo Roden


In a low level and uncommon operation like this, there is no standartized way to generate a RAM Disk, it is platform dependent and hence there is no functionality of this in NodeJS and there won't be likely, you have to write an extension. In Windows, it will call ramdisk.exe (not so familiar with it) and on Linux it is availalbe under /dev/shm , which you can resize by mount options later. So, the best way is to find the best external program for Windows versions, and in Linux just mount and use the /dev/shm like a normal folder.

More Info on /dev/shm

Solution courtesy of: Mustafa


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How do I create a RAM disk using Node.js?


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription