How to store objects locally in an array or another data structure without using database in node js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to store objects locally in an array or another data structure without using database in node js

So I have this situation, I have a json data and I must store it as objects in an array or a hash map but I m not allowed to use databases since I want to store it temporarily until I close the program. How can I do this I m sure there is a way to do it. When I declare an array it and store my objects there, when I call push method another time than that data will be replaced with the new data which I don't want to do. I want the data to stay stored in that array and when I run the program another time and push new data to the array that the new data will be appended to the array and not replace the last data that I stored there. How can I do this guy's, who was in this situation before. I ll appreciate any help

25th Mar 2019, 9:32 AM
Nidhal Baccouri
Nidhal Baccouri - avatar
2 Answers
0
You could use the localStorage (native js) or try to store it in a text file (using JSON.stringify and JSON.parse in both cases) ?
26th Mar 2019, 6:30 AM
Dyf Dyf
Dyf Dyf - avatar
0
I can't use localstorage in this case I think, I cant use txt file too because I want to save objects containing a sub object and an ID to that object. I tried to use json to append objects to that txt file and then tried to read that file but it didn't work. In json we can't store objects containing objects I think! Maybe I'm wrong If you have a way correct me
26th Mar 2019, 9:42 AM
Nidhal Baccouri
Nidhal Baccouri - avatar