I'm trying to push names in a json file. I'm trying to do something like:
socket.on('create json', function(data){
var data = JSON.stringify(Data, null, 2);
fs.writeFile('participants.json', data)
console.log(data);
});
This is only outputting the data that I've send and results in:
{
"type": "Buffer",
"data": [34,69,120,97,109,112,108,101,32,110,97,109,101, 34 ]
}
When I'm writing the file it deletes everything and puts that in. I'm looking for a way to write:
{
"names":["name1", "name2", "name3"]
}
Any ideas on how to fix and write this?
Help is very much appreciated!