I am using express 3.5 js. What I am trying to do is, get the form elements store it in a variable data as JSON and send it back to the server and update the JSON in the server.
In the browser I get the json output as {"name-check":true,"name-text":"someName","dest-check":false,"destination-text":"someplace"}
app.post('/json/*.json', function(req, res) {
var outputFilename = '/tmp/my.json';
var mydata = req.body;
fs.writeFile(outputFilename, mydata , function(err) {
if (err) {
console.log(err);
} else {
console.log("JSON saved to " + outputFilename);
}
});
When I try to update the json with the data from the form, it doesn't work.
I tried this post How can I pretty-print JSON using node.js? which works as long as I have the data in the same file, but doesn't work when getting it from the form.