Is it possible to save the Map to the disk as a binary format and read it into a Map later on with Node.js?
There is no built-in facility for that. A Map is just an association between a set of keys and values. And, if you do
let summaryArray = Array.from(yourMapObject);
summaryArray
will be something like this:
[['key1', value1], ['key2', value2]]
Then, assuming your Map object contains things (both keys and values) that can be expressed in JSON (not symbols and not objects with circular references and not custom object types), you can easily save that summaryArray
to JSON.
Furthermore, you can regenerate the Map object by reading the JSON from disk, parsing it back into the summaryArray
form and passing that to the Map
constructor.
let yourMapObject = new Map(summaryArray);
If your Map object does contain things that can't be expressed in JSON, then you will have to invent your own way of storing those things or converting them to/from something that can be expressed in JSON.