1
I want to record two or more names in a JSON file. However, when I try to do this, it saves only the last information.
My job:
async function grava_login(){
fs.writeFile("data.json", JSON.stringify({name: "Mohamed Almaci",
name:"Masq"}),"utf8", async function(err){
try{
if(err){
console.log(err);
}
else{
console.log("The file was saved!");
}
}
catch{
console.log("Erro ao salvar dados no arquivo json!")
}
})}
How I want JSON to stay:
{
"name": "Mohamed almaci",
"name": "Masq"
}
How the JSON is:
{
"name":"Masq"
}
You are writing the
name
in makingname="Masq"
. If you assign another key, for examplename1: "Masq"
, he will not write and then will be saved the whole object{ 
 name: "Mohamed almaci",
 name1: "Masq"
}
in the archive.– Cmte Cardeal
I realized that I am writing but I saw people doing it the way I want and working, I saw an example was with email, and the person managed to do the same thing I want, but it wasn’t with Ode and it was about another theme so I couldn’t figure out how to do it by Node js with lib Fs.
– user212376
Look at this sample video https://youtu.be/iiADhChRriM minute 8:44 notice that he used name twice, but I can’t do this. I’ve tried every way.
– user212376