I have the need to load an array of objects that are stored in a text file to be used as an array in my code. The text file looks like this..
[{"ip":"195.54.160.149","date":"2021-12-30T18:47:06.570Z","url":"/"},
{"ip":"92.118.234.202","date":"2021-12-30T18:55:41.886Z","url":"http://azenv.net/"}]
when I read the file and then set my var to the data from the txt file
readBlacklist: function() {
fs.readFile(file, 'utf8' , (err, data) => {
if (err) {
console.error(err);
return
}
this.accesslog = data
});
},
I get an error when i want to push any new objects into my this.accesslog. So my question is, is there a fast way to read from file and set the data of this.accesslog to the file data and still make it be recognized as an Array of objects or do i need to read the file and then loop thru it and push each object into the array ?
One of the issues is that I don’t know if the Object will always end with a n so i cant use a newline as a separator, I know it will always be an object which will start with a { and end with a }