I'm trying to write/add data in a json file (for example for each request, a new json is added in the json file) i am using Express.js. I am new to all of this so I really don't know what to do. I'm using a POST request, here's what i got so far. I know it's a big catastrophic mess, i scraped everything that could help me and gathered all of it. I'm just SO lost. Thanks for your help !
app.post('*/', function(req, res) {
res={
first_name: req.body.first_name,
last_name: req.body.last_name,
reponse1: req.body.reponse1,
reponse2: req.body.reponse2,
};
JSON.stringify(res);
var body = {
table: []
};
body.table.push(res);
filePath = __dirname + '/data.json';
req.on('data', function(data) {
body += data;
});
req.on('end', function (){
fs.appendFile(filePath, body, function() {
res.end();
});
});
});