-2
You guys, I got this comic:
const fs = require('fs');
const produto = {
nome: 'Smartphone',
preco: 1749.99,
descontoo: 0.15
}
fs.appendFile('mynewfile2.txt',
JSON.stringify(produto), err => {
console.log(err || 'Arquivo salvo');
});
Note that every time I run the comic it will repeat the information, but I want you not to repeat the same information, but I want to achieve this result in a simple way without changing much in the comic if possible. It is that I was answering a person here in stack overflow and I gave this answer and a comment made me see this problem, but I use the appendFile
and I wonder if there’s any way to do that without needing to almost rewrite the entire comic
What do you mean by "repeat information"? Always save the same data?
– Luiz Felipe
Yes, it was this question that I was referring to, I would like to know if there is how not to repeat data (or duplicate information) without needing to change the code a lot, as in that example that you pointed out in another question.
– Dakota
Is that I use the
appendFile
quite ... And that left me curious should kk.– Dakota
You came to look at the code I posted as a comment on your reply? See you again here. Note that it does not overwrite the data, only adds a new element at the end of the array... Replacing the file contents (with a new, incremented one) is different from replacing the information.
– Luiz Felipe
I tried to run over returned me an error in import, and even if I use require to import the modules etc, it returns me another error in
JSON.parse(data?.trim() | | '[]')
I couldn’t execute the code to better understand, so I asked the other question.– Dakota
Must be my version of Node js I believe
– Dakota
Try this.
– Luiz Felipe
That worked out hehe I will edit the answer, I had understood something else kkk I spent a long time trying to solve that.
– Dakota