const fs = require('fs');
const express = require('express');
const app = express();
app.use(express.json());
app.get('/submit', (req, res) => {
let Com_Title = req.query.ComTitle;
let Com_Text = req.query.ComText;
let data = {
Title: Com_Title,
Text: Com_Text,
}
console.log(data);
let jsonData = JSON.stringify(data);
// fs.writeFileSync('notes.json', dataJSON)
// let MyData = JSON.parse(jsonData);
fs.appendFileSync('ComplaintFile.json', jsonData, err => {
if (err) {
console.log(err);
res.sendStatus(404).end();
}
console.log('Data Added');
res.send('Added');
})
});
let port = 8080;
app.listen(port, () => {
console.log("Listening to 8080");
})
{
"Title": "School Events",
"Text": "Exciting activities and workshops"
}{
"Title": "Summer Vacation",
"Text": "Relaxing by the beach"
}
I am encountering an issue with saving data in a JSON file. It seems that when I add new data, it is not separated properly with commas in the file.
Has anyone else faced this problem before?