W
W
Windyay2022-04-11 18:02:23
JavaScript
Windyay, 2022-04-11 18:02:23

How to work correctly with data?

Good afternoon, please help, I can't figure out how to implement the following:
I write the received data
fs.appendFile('./data.txt', JSON.stringify(data));
I get an array of objects,
then I get this data

fs.readFile("./data.txt", "utf8", 
function(error,r){
  if(error) throw error; 
  datafixed = JSON.parse(('['+r+']').replace(/\]\[/g,'],['));
  data = datafixed.flat(Infinity)
  createitem();
});

i want to re-fetch the data that matches (partially) with the data that is in my parsed array/txt file
and leave only the new data
conditionally i accessed the data, got [{product: bread}, {product: milk},{product : butter}] wrote it to a txt file, then parsed it, worked with the data,
then I re-requested I get [{product: bread}, {product: milk}, {product: butter}, {product: kefir} ]
I want to have I only have kefir in the array and also in the txt file
. If I understand how to iterate through the array (after parsing) and remove the same elements (I google it), then how and at what stage should I also clear the txt file, I don’t understand
Txt file is my mini database, because I haven't worked with databases yet
I would be grateful for any advice

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2022-04-11
@Windyay

Get started with databases. They are specially made for this. Get started with Redis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question