what i exactly want is to store some Data Locally in a Array of Objects in my Program so that i can use that Data all day long and by the End of the Day i want to delete it without the use of Databases. I have a Json data and i want to Store them as object with a universally unique identifier (uuid) in an Array or data Structure so that i can use it in my Program, i cant use a Database, i think i must find a way to store the Objects in a global Array but i want to append new Objects to that Array without deleting the Objects that are already stored in that Array. I'm using Node js, I'm pretty sure there is a way to do this but i dont know how. I ll apreciate some Help
I tried to Declare classes with Array Property and Store my Data in that Array but when i reexecute the code, the data is deleted and i lost my Data, but i must find a way like a Local Storage in a global Array where my Data will be safe if I append some Objects to that Array and I'm Ok if that Data will be deleted at the End of the Day if I turn off my Laptop for example or if I end the Program and close Vs Code. I tried also to declare it in extra files and call it from the main program but nothing worked
// this is a library to create a universilly unique id const uuid = require("uuid/v1");
var todo_list = { todos: [],
register : function(todo) {
this.todos.push({
id : uuid(),
todo: todo
})},
size : function() {return this.todos.length },
display : function() {
this.todos.forEach(t=> {
console.log(t);
});
}
}
function createtodo(id, name, region) {
return {
id : id,
name : name,
region : region
};
}
todo_list.register(createtodo(2,"test6", "leipzig"));
console.log(todo_list.size());
console.log(todo_list.display());
i expect that when a register a new todo that it ll be appended in the todos Array Property and not replace what actually inside the todos in the moment. If i call the function register 5 times then 5 objects will be stored in my todos Array but if I Comment the code of register function calling and execute the Program another time, then my data will be lost and the result of the size function will be 0 or undifined. the result that i want is that my data will be stored in an extra global Array where the data will not be lost even after i change the code but i understand that the data will be lost if i close the program somehow