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

2019-05-03 02:50发布

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)?

1条回答
劳资没心,怎么记你
2楼-- · 2019-05-03 03:26

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

查看更多
登录 后发表回答