Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I store a file in "memory" with Node.js?

Tags:

I'm doing some file manipulation work with node.js and many of the packages that I use require a "path" to be sent so that they can open the file, do some work, and so on.

But I'm parsing millions of files and rather than actually store them on disk, I'd like to store them in memory. The contents of the files are all in my database and I'd hate to write them to disk, just to do my insanely awesome work on them.

So is such a thing possible?

like image 536
Shamoon Avatar asked May 23 '14 14:05

Shamoon


People also ask

Is Nodejs memory safe?

They are absolutely NOT SAFE.

Can we store data in node JS?

Storing your Node. js application's configuration data is quite simple - every object in JavaScript can be easily rendered as JSON, which in turn is just string data that can be sent or saved any way you'd like. The simplest way to do this involves the built-in JSON. parse() and JSON.

How does node js handle memory?

Memory Management in Node.Memory management provides ways to dynamically allocate memory chunks for programs when they request it, and free them when they are no longer needed – so that they can be reused. Application-level memory management can be manual or automatic.


2 Answers

It looks like it's possible look at this article how to do it creating writable memory stream

like image 76
user3210416 Avatar answered Sep 16 '22 18:09

user3210416


You can use memfs, which is an in-memory filesystem for Node.js.

like image 28
Vad Avatar answered Sep 17 '22 18:09

Vad