Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 673
Golo Roden Avatar asked Jan 15 '13 16:01

Golo Roden


People also ask

How to get system memory in Node JS?

Throughout this post we have described how to obtain the system memory using a very simple os module of Node js. The os module provides a simple freemem () and totalmem () methods that returns the total as well as the available system RAM in Node js. We hope this guide has helped you.

How to create a directory using NodeJS?

- GeeksforGeeks How to create a directory using Node.js ? In this article, we will create a directory using NodeJS. NodeJS has Filesystem (fs) core module, which enables interacting with the file system, has Node.js fs.mkdir () method or Node.js fs.mkdirSync () method method, to create new directory /parent directory.

How to delete a folder in Node JS?

Removing a folder: If we want to delete a given directory, we can use Node.js fs.rmdir () Method or Node.js fs.rmdirSync () Method, it will become complicated if the directory contain some file content. So we can use a third party package fs-extra provided by npm to delete the given directory. Let’s install the given package using npm.


1 Answers

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

like image 54
Mustafa Avatar answered Oct 19 '22 04:10

Mustafa